在下面的代碼中,我遵循一個過程來創建一個隨機正定矩陣P。Matlab等式逼近如何工作?
首先,我創建奇異值分解[U,S,V]的隨機陣列的甲,我試圖驗證實際上U '* U == U * U'= I(其中I是單位矩陣),其從理論上已知。問題是,如果我自己檢查矩陣的內容,我可以驗證,但是Matlab產生的邏輯矩陣不能驗證,因爲零表示爲-0.000或0.0000,所以只有符號匹配時結果爲1。這是爲什麼?
但更大的問題出現在幾行低於此,其中正定(其所有特徵值是正的)矩陣P產生和我只是想檢查P = P」。通過點擊x和y,我可以看到它們的內容完全相同,但Matlab無法驗證這一點。我不明白爲什麼會發生這種情況,因爲在這種情況下,我們正在談論相同的變量P這裏只是轉置。
下面是代碼:
%Dimension of the problem
n = 100;
%Random matrix A
A = rand(n, n)*10 - 5;
%Singular value decomposition
[U, S, V] = svd(A);
%Verification that U*U'=U'*U=I
U'*U == U*U'
%Minimum eigenvalue of S
l_min = min(diag(S));
%Maximum eigenvalue of S
l_max = max(diag(S));
%The rest of the eigenvalues are distributed randomly between the minimum
%and the maximum value
z = l_min + (l_max - l_min)*rand(n - 2, 1);
%The vector of the eigenvalues
eig_p = [l_min; l_max; z];
%The Lambda diagonal matrix
Lambda = diag(eig_p);
%The P matrix
P = U*Lambda*U';
%Verification that P is positive definite
all(eig(P) > 0)
%Verification that P=P'
x=P;
y=P';
x==y