inverse of matrix times vector
2 ビュー (過去 30 日間)
古いコメントを表示
Dear all:
The following code computes the inverse of a matrix times a column vector using the LU decomposition. The result is supposed to be a a covariance matrix, i.e., symmetric, positive semi-definite.
% create arrays
D = [-0.8710, 1.1870, -0.4511;
1, 0, 0
0, 1, 0];
R = [1; zeros(8,1)];
A = eye(9) - kron(D,D);
% compute inverse of A times vectorized R using LU decomposition
[L, U] = lu(A);
z = L\R;
x = U\z;
% random draw
gamma = reshape(x,3,3);
mvnrnd(zeros(1,3),gamma)
However, MATLAB returns an error that gamma is not symmetric, positive semi-definite. My hunch is that there is a problem with floating point arithmetic when computing the inverse. Other values for D work fine, but this particular example does not.
Any hints will be greatly appreciated.
Thanks, Peter
0 件のコメント
採用された回答
Christine Tobler
2018 年 3 月 21 日
The problem is probably that the vector x is not exactly symmetric (because of floating-point errors). You can try just symmetrizing gamma:
gamma = (gamma + gamma')/2;
Based on what right-hand size is used, I think it's still possible for gamma to be singular.
If you have the Control Toolbox, you could use dlyap instead, which will return a symmetric result, or even dlyapchol to guarantee a positive definite result.
2 件のコメント
Christine Tobler
2018 年 3 月 22 日
X = dlyap(A,Q) solves the discrete-time Lyapunov equation
A*X*A' − X + Q = 0
so I think passing in D and reshape(R, [3 3]) should solve your problem.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Computations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!