next up previous
Next: About this document ... Up: Math98 lab 2 Previous: Symmetric and skew symmetric

Solve the linear system:

Solving AX = b:

If A is a rectangular matrix and you want to find the general solution of AX=B, first enter the augmented matrix of the system by typing C=[A b], then type rref(C). (Shortcut: rref ([A b]) )

Example :

Solve the linear system:


\begin{displaymath}\begin{array}{llll} 2x_1& +4x_2 &-2x_3 &=0\\
3x_1&+5x_2 & &=1\\
\end{array}\end{displaymath}

Enter the augmented matrix

$M = \left[ \begin{array}{llll}
2&4&-2&0\\
3&5&0&1 \\
\end{array} \right] $

then type rref(M).

You will see


\begin{displaymath}\left[ \begin{array}{llll}
1 & 0&5&2\\
0&1&-3 &-1\\
\end{array} \right] .
\end{displaymath}

The corresponding system of equations is:

$ \begin{array}{llll}
x_1& &+5x_3 &=2\\
& x_2 & -3x_3 &=-1\\
\end{array}$

Now, using the parameter $t$ to represent the $nonleading$ variable $x_3$, we have the general solution:

$x_1= 2-5t$,
$x_2= -1+3t,$
$x_3 =t$

Now you can use MATLAB's command X=A $\backslash$ b to solve this system:

type

X = [ 2 4 -2; 3 5 0 ] $\backslash$ [0; 1]

Try to solve the following inconsistent system of equations:


\begin{displaymath}\begin{array}{llll}
2x_1& +4x_2 &-2x_3 &=0\\
3x_1&+5x_2 & &=1\\
4x_1& +8x_2 &-4x_3 &=3
\end{array}\end{displaymath}

You can enter the augmented matrix of this linear system as

AG= [ 2 4 -2 0; 3 5 0 1; 4 8 -4 3]

The RREF of the augmented matrix should come out ( using rref(AG) )to be


\begin{displaymath}\begin{array}{rrrr}
1&0&5&0 \\
0&1&-3 &0 \\
0&0&0& 1\\
\end{array}\end{displaymath}

with the corresponding system of equations,


\begin{displaymath}\begin{array}{llll}
x_1& &+5x_3 &=0\\
& x_2 & -3x_3 &=0\\
0 &+0&+0&=1\\
\end{array}\end{displaymath}

which is inconsistent( Explain Why, by typing % and then your comment.)

Special Case:

Now type the coefficient matrix:


\begin{displaymath}AC= [ 2 4 -2 ; 3 5 0 ; 4 8 -4 ] \end{displaymath}

and the constant matrix as

\begin{displaymath}b= [ 0 1  3]' \end{displaymath}

or as

\begin{displaymath}b=[ 0; 1 ; 3] \end{displaymath}

then use MATLAB's command

X= AC$\backslash$ b

Is it confirming your findings about this linear system?

Example: Enter

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

and

B=[3 6 7 ]'.

Type X = A$\backslash$ B

What do you see? Check the answer.

Replace $A$ with a non-invertible 3 by 3 matrix and try to solve $AX = B$ by using $X = A \backslash B$. Explain the warning.


next up previous
Next: About this document ... Up: Math98 lab 2 Previous: Symmetric and skew symmetric