[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Solving Systems Of Linear Equations
From: |
Paul Kienzle |
Subject: |
Re: Solving Systems Of Linear Equations |
Date: |
Mon, 05 May 2003 21:49:45 -0400 |
User-agent: |
Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.3) Gecko/20030312 |
Mike Miller wrote:
...which is my representation of a matrix times a column vector with the
product equal to a column vector. Or...
M x = b
So take the inverse of M and multiply that inverse times b, and you have
your answer:
x = inv(M)*b
That's basically what you do in Octave. Here's how I did it:
Except that you don't really want to use inv(M) because it is
more expensive and less stable than it needs to be. Instead
use
x = M \ b;
which more or less does it how you would in linear algebra
class, with forward elimination and back substitution. The
algorithm rearranges the equations to minimize rounding
errors. If your matrix is very unstable, you will want to
use the more expensive but more stable QR decomposition:
[Q,R,P] = qr(M,0);
x = R \ (Q' * b);
x(P) = p;
Hope that helps,
Paul Kienzle
address@hidden
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------