Reputation: 3405
in matlab inverse of matlab can be written:
For least squares ( more efficient)
x = A\b.--------------------------------1
But for covariance matrix (Qxx) of unknown paramters(x), I usually do,
Qxx==inv(A) --------------------------2
How I can write it in efficient way like (1)?
Upvotes: 0
Views: 2094
Reputation: 12345
If you actually need an inverse, then you will not be able to beat the inv
function.
For some discussion on the inv
function what what it should be used for see this article by Loren on the Art of Matlab. As you note in the original question, and Loren notes in the linked article, and I feel the need to reinforce here; if you do not actually need an inverse, then you are better off avoiding this step. But that is not always possible.
If you actually need an inverse, then just use the inv
function.
Upvotes: 3
Reputation: 6887
You mean something like:
Qxx = A \ eye(size(A));
?
Real question is, what are you doing with the inverse? If you're just remultiplying it by some other vector c
then you can just do...
A \ c
instead of Qxx * c
Upvotes: 1