inverse of matrix times vector

2 ビュー (過去 30 日間)
Peter
Peter 2018 年 3 月 21 日
コメント済み: Christine Tobler 2018 年 3 月 22 日
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

採用された回答

Christine Tobler
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 件のコメント
Peter
Peter 2018 年 3 月 22 日
編集済み: Peter 2018 年 3 月 22 日
Thanks, Christine. I was hoping for an elegant (i.e., numerically robust) way to solve the problem (maybe the other two commands you suggest are, but I don't know anything about Lyapunov equations). Of course, your solution works like a charm.
Christine Tobler
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 ExchangeMatrix Computations についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by