0

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)?

Amro
  • 123,847
  • 25
  • 243
  • 454
Shahgee
  • 3,303
  • 8
  • 49
  • 81
  • Not sure I understand the question. If you explicitly need the inverse of a matrix, then you need to call `inv`. If you don't (as in the case of solving a set of linear equations), then you don't need to. – Oliver Charlesworth Apr 09 '12 at 16:03
  • What do you mean by 'more efficient'? Inverting a matrix tends to be a bad way of solving almost any problem - what exactly are you trying to do? – James Apr 09 '12 at 16:04

2 Answers2

3

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.

Pursuit
  • 12,285
  • 1
  • 25
  • 41
  • "If you actually need an inverse, then you will not be able to beat the `inv` function." That's not at all what I took from this link and discussion. – Chris A. Apr 09 '12 at 19:54
  • True, I reformatted a little bit. The initial statement stands on its own, everything else is really musing on when it is actually required. – Pursuit Apr 10 '12 at 00:25
1

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

Chris A.
  • 6,817
  • 2
  • 25
  • 43