# Section 2.2 $\qquad$ Solving Linear Systems

### Example 1

Solve the linear system whose augmented matrix has the echelon form:
$$
  \left[
     \begin{array}{ccc|c}
       1 & 2 & 0 & 3 \\
       0 & 1 & 1 & 2 \\
       0 & 0 & 1 & -1 \\
     \end{array}
   \right]
$$


```python
from numpy import *
from numpy.linalg import solve

A = array([[1, 2, 0], [0, 1, 1], [0, 0, 1]]);
b = array([3, 2, -1]);

solve(A, b)
```




    array([-3.,  3., -1.])



To solve a linear system $A\mathbf{x}=\mathbf{b}$,
- form the augmented matrix
<br /><br />
- transform to a matrix $[C~|~\mathbf{d}]$ in
<br /><br />
- find solution of the linear system w.r.t. $[C~|~\mathbf{d}]$ using
<br /><br />
**Remark:**
<br /><br /><br /><br />

If $A$ is $n\times n$, and the linear system $A\mathbf{x}=\mathbf{b}$ has a unique solution, then
<br /><br /><br /><br />

### Example 2

Solve the linear system
\begin{eqnarray*}
  x+2y+3z &=& 9 \\
  2x-y+z &=& 8 \\
  3x-z &=& 3
\end{eqnarray*}


```python
from numpy import *
from numpy.linalg import solve

A = array([[1, 2, 3], [2, -1, 1], [3, 0, -1]]);
b = array([9, 8, 3]);

solve(A,b)
```




    array([ 2., -1.,  3.])



In general, $A$ is $m\times n$ and the augmented matrix $[C~|~\mathbf{d}]$ might have the following form
\begin{equation*}
  \left[
    \begin{array}{ccccc|c}
      1 & c_{12} & \cdots &  & c_{1n} &  d_1 \\
      0 & 1 & c_{23} & \cdots &   c_{2n} & d_2 \\
      \vdots & \vdots & \ddots & \ddots &  &  \\
      0 & 0  &  & 1 & c_{k-1,n} & d_{k-1} \\
      0 & 0 & \cdots & 0 &  c_{k,n}& d_k \\
      0 & 0 & \cdots &  &  0& d_{k+1} \\
      \vdots & \vdots &  &  &\vdots  &  \\
      0 & 0 & \cdots &  &  0& d_{m} \\
    \end{array}
  \right]
\end{equation*}
- If $d_{k+1} = 1$,
<br /><br />
- If $d_{k+1} = 0$, $c_{k,n} = 1$
<br /><br />
- If $c_{k,n} = 0$
<br /><br />

### Example 3

Let
\begin{equation*}
  [C~|~\mathbf{d}] = \left[
        \begin{array}{ccccc|c}
          1 & 2 & 3 & 4 & 5 & 6 \\
          0 & 1 & 2 & 3 & -1 & 7 \\
          0 & 0 & 1 & 2 & 3 & 7 \\
          0 & 0 & 0 & 1 & 2 & 9 \\
        \end{array}
      \right].
\end{equation*}
<br /><br /><br /><br /><br /><br /><br />

### Example 4

Let
\begin{equation*}
  [C~|~\mathbf{d}] = \left[
        \begin{array}{cccc|c}
          1 & 2 & 3 & 4 & 5 \\
          0 & 1 & 2 & 3 & 6 \\
          0 & 0 & 0 & 0 & 1 \\
        \end{array}
      \right].
\end{equation*}
<br /><br /><br /><br /><br /><br /><br />

### Example 5

Solve the linear system
\begin{eqnarray*}
% \nonumber to remove numbering (before each equation)
  x+2y+3z &=& 6 \\
  2x-3y+2z &=& 14 \\
  3x+y-z &=& -2
\end{eqnarray*}


```python
from numpy import *
from numpy.linalg import solve

A = array([[1, 2, 3], [2, -3, 2], [3, 1, -1]]);
b = array([6, 14, -2]);

solve(A,b)
```




    array([ 1., -2.,  3.])



## Homogeneous System

### Example 6

Solve the linear system
\begin{eqnarray*}
% \nonumber to remove numbering (before each equation)
  x+y+z+w &=& 0 \\
  x+w &=& 0 \\
  x+2y+z &=& 0
\end{eqnarray*}


```python
from sympy import *

x, y, z, w = symbols('x y z w');

eq1 = x + y + z + w;
eq2 = x + w;
eq3 = x + 2*y + z;

solve([eq1, eq2, eq3], (x, y, z, w))
```




    {x: -w, y: w, z: -w}



**Remark:**
<br /><br /><br /><br />

## Relationship between nonhomogeneous and homogeneous systems

Let $A\mathbf{x}=\mathbf{b}$, $\mathbf{b}\neq\mathbf{0}$ be a consistent system. The associated homogeneous system is
<br /><br /><br /><br />
- 
<br /><br /><br /><br />
- 
<br /><br /><br /><br />

fed1c9f480ddae61bc62b0e05345b511290cdd44
ipynb
Jupyter Notebook
Jupyter_Notes/Lecture06_Sec2-2_SolvLinSyst.ipynb
xiuquan0418/MAT341
2fb7ec4e5f0771f10719cb5e4a00a7ab07c49b59
MIT
Jupyter_Notes/Lecture06_Sec2-2_SolvLinSyst.ipynb
xiuquan0418/MAT341
2fb7ec4e5f0771f10719cb5e4a00a7ab07c49b59
MIT
Jupyter_Notes/Lecture06_Sec2-2_SolvLinSyst.ipynb
xiuquan0418/MAT341
2fb7ec4e5f0771f10719cb5e4a00a7ab07c49b59
MIT
Qwen/Qwen-72B
1. YES
2. YES