固有値、固有ベクトル、スペクトル分解、特異値分解、コレスキー分解
プログラム
#include<oxstd.h>
main()
{
decl A,lambda,P;
A=<1,2;2,10>;
print("A=",A);
eigen(A,&lambda,&P);
// eigensym can also be used.
print("eigenvalues of A:",lambda);
print("eigenvectors of A:", P);
P[ ][0]/=sqrt(sumsqrc(P[ ][0]));
P[ ][1]/=sqrt(sumsqrc(P[ ][1]));
print("eigenvectors(length=1) of A:", P);
// Check PP'=I
print("P'P=",P'P);
// Singular Value Decomposition
decl U,W,V;
decsvd(A, &U, &W, &V);
print("U=",U,"W=",W,"V=",V);
print("UVW'=",U*diag(W)*V');
// Choleski Decomposition
decl L;
L=choleski(A);
print("L=",L, "LL'=",L*L');
}
計算結果
A=
1.0000 2.0000
2.0000 10.000
eigenvalues of A:
0.57557 10.424
eigenvectors of A:
1.0000 0.21221
-0.21221 1.0000
eigenvectors(length=1) of A:
0.97822 0.20759
-0.20759 0.97822
P'P=
1.0000 0.00000
0.00000 1.0000
U=
-0.20759 -0.97822
-0.97822 0.20759
W=
10.424 0.57557
V=
-0.20759 -0.97822
-0.97822 0.20759
UVW'=
1.0000 2.0000
2.0000 10.000
L=
1.0000 0.00000
2.0000 2.4495
LL'=
1.0000 2.0000
2.0000 10.000