next up previous
Next: Stuff to Hand In Up: Warmup Previous: Entering Matrices

Linear Systems

Let's try to get the computer to solve the system

\begin{eqnarraystar}
x_1 - 2 x_2 + x_3 &=& 1\  3x_1 + x_2 - 4x_3 &=& 0\  2x_1 + 2 x_2 - x_3 &=& 2\end{eqnarraystar}

The first thing to do is to represent it as a matrix equation. The coefficient matrix is

\begin{displaymath}
A = \left[\begin{array}
{rrr}
 1&-2&1\  3&1&-4\  2&2&-1
 \end{array}\right]\end{displaymath}

and the forcing matrix is

\begin{displaymath}
B = \left[\begin{array}
{r}
 1\ 0\ 2
 \end{array}\right]\end{displaymath}

The system can be abbreviated as AX=B. After you enter the matrices A and B (do it now!), you can ask Matlab or Octave to solve the system by Gaussian elimination. Just row reduce the augmented matrix with the command
  rref([A,B])
and read off the solutions. Do it now![*]

Alternatively, you can ask Matlab or Octave to calculate X by ``dividing'' the equation AX=B by A on the left (since the factor A is on the left). Left division is indicated by a backslash:

  X = A\B
Try it now. You should get the same answer that you got from Gaussian elimination. Note, however, that left division will only produce one solution, even if the system has infinitely many solutions.



Frank Beatrous
1/20/1998