help-octave
[Top][All Lists]

## Re: Solving Systems Of Linear Equations

 From: Mike Miller Subject: Re: Solving Systems Of Linear Equations Date: Mon, 5 May 2003 19:59:14 -0500 (CDT)

```On Mon, 5 May 2003, Lauren Sorenson wrote:

> Question:  Solve this System of Linear Equations
>
> 2W+5X-Y+4Z=0
> W+X+Y+Z=0
> 4W-3X+6Y+Z=0
> 2W-5X-3Y-Z=7

That's the same as...

[ 2  5 -1  4|  [W| = [0|
| 1  1  1  1|  |X| = |0|
| 4 -3  6  1|  |Y| = |0|
| 2 -5 -3 -1]  |Z] = |7]

...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

x = inv(M)*b

That's basically what you do in Octave.  Here's how I did it:

octave:1> M =[ 2  5 -1  4 ;  1  1  1  1 ;  4 -3  6  1 ; 2 -5 -3 -1]
M =

2   5  -1   4
1   1   1   1
4  -3   6   1
2  -5  -3  -1

octave:2> b=[0 0 0 7]'
b =

0
0
0
7

octave:3> x=inv(M)*b
x =

3.00000
1.00000
-1.00000
-3.00000

So, W=3, X=1, Y=-1 and Z=-3.

Best,

Mike

--
Michael B. Miller, Ph.D.
Assistant Professor
Division of Epidemiology
and Institute of Human Genetics
University of Minnesota
http://taxa.epi.umn.edu/~mbmiller/

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

```