# Linear Algebra/Systems of Linear Equations
## Systems of Linear Equations

An important problem in Linear Algebra is in solving the system of m linear equations of n variables in a field F:
$a_{11}x_{1}+a_{12}x_{2}+...+a_{1n}x_{n}=b_{1}$ $a_{21}x_{1}+a_{22}x_{2}+...+a_{2n}x_{n}=b_{2}$ ... $a_{m1}x_{1}+a_{m2}x_{2}+...+a_{mn}x_{n}=b_{m}$.
Where all $a_{ij}$ are elements of a field.
An example of a system of linear equations is: Linear system (2):
    $2x_{1}-x_{2}+1.5x_{3}=8$
    $x_{1}-4x_{3}=-7$
A solution of the system is a list $\left(s_{1},s_{2},...,s_{n}\right)$ of numbers that makes each equation true, when the values $s_{1},s_{2},...s_{n}$ are substituted for $x_{1},...,x_{n}$ respectively. For example, $\left(5,6.5,3\right)$ is a solution to the system (2) because, when these values are substituted in (2) for $x_{1},x_{2},x_{3}$ respectively, the equations simplify to $8=8$ and $-7=-7$.
The set of all possible solutions is called the solution set of the linear system. Two linear systems are called equivalent if they have the same solution set. That is, each solution of the first system is a solution to the second system, and vice versa.
Finding the solution set of a system ot two linear equations in two variables is easy because it is the same as finding the intersection point of two lines. A typical problem is
    $x_{1}-3x_{2}=-1$
    $-x_{1}+4x_{2}=3$
The graphs of these lines, which we denote by $l_{1}$ and $l_{2}$. A pair of numbers $\left(x_{1},x_{2}\right)$ statisfies both equations in the system if and only if the point $\left(x_{1},x_{2}\right)$ lies on both $l_{1}$ and $l_{2}$. In the system above, the solution is the single point $\left(5,2\right)$, as you easily can see on Figure 1.
Of course, two lines do not have to intersect in a single point, they could be parallel, or they could coincide and "intersect" at every point on the line. Figure 2 and Figure 3 shows graphs to visualize this.
A system of linear equations is said to be consistent if it has either one solution or infinitely many solutions, and a systems is said to be inconsistent if it has no solution.
In Linear Algebra, we are concerned with three problems:
* Is a system of linear equations consistent or not?
* If so, how many elements are in the solution set?
* What is the solution set?

## Motivation

Systems of linear equations are common in science and mathematics. These two examples from high school science give a sense of how they arise.
The first example is from Physics. Suppose that we are given three objects, one with a mass known to be 2 kg, and are asked to find the unknown masses. Suppose further that experimentation with a meter stick produces these two balances.
Since the sum of moments on the left of each balance equals the sum of moments on the right (the moment of an object is its mass times its distance from the balance point), the two balances give this system of two equations.
    $40h+15c=100$
    $25c=50+50h$
The second example of a linear system is from Chemistry. We can mix, under controlled conditions, toluene C$_7$H$_8$ and nitric acid HNO$_3$ to produce trinitrotoluene C$_7$H$_5$O$_6$N$_3$ along with the byproduct water (conditions have to be controlled very well, indeed— trinitrotoluene is better known as TNT). In what proportion should those components be mixed? The number of atoms of each element present before the reaction
    $x\,{\rm {C}}_{7}{\rm {H}}_{8}\ +\ y\,{\rm {H}}{\rm {N}}{\rm {O}}_{3}\longrightarrow z\,{\rm {C}}_{7}{\rm {H}}_{5}{\rm {O}}_{6}{\rm {N}}_{3}\ +\ w\,{\rm {H}}_{2}{\rm {O}}$
must equal the number present afterward. Applying that principle to the elements C, H, N, and O in turn gives this system.
    ${\begin{matrix}7x=7z\\8x+1y=5z+2w\\1y=3z\\3y=6z+1w\end{matrix}}$
To finish each of these examples requires solving a system of equations. In each, the equations involve only the first power of the variables. This chapter gives an introduction to systems of linear equations. We will solve them later.

## Matrix Notation

The essential information of a linear system can be described in a rectangular array called a matrix. Given the system
    $3x_{1}+5x_{2}+2x_{3}=0$
    $x_{1}-8x_{2}=10$
    $-2x_{2}+x_{3}=-8$
with the coefficients of each variable aligned in columns, we make a matrix called the coefficient matrix (or matrix of coeffients) of the system. The coefficient matrix looks like this
    ${\begin{bmatrix}3&&5&&2\\1&&-8&&0\\0&&-2&&1\end{bmatrix}}$
Which make sense if you look at the definition of a linear equation (1). The second row contains a zero because the second equation could be written as $x_{1}-8x_{2}+0x_{3}=10$
We also have a matrix called the augmented matrix which for the same system looks like this
    ${\begin{bmatrix}3&&5&&2&&0\\1&&-8&&0&&10\\0&&-2&&1&&-8\end{bmatrix}}$
An augmented matrix of a system consists of the coefficient matrix with an added column containing the constants from the right sides of the equation. Again look at the linear equation definition (1), if it does not make sense.
The size of a matrix tells us how many rows and columns it has. The augmented matrix above has 3 rows and 4 columns, therefore it is called a 3x4 (read "3 by 4") matrix. m and n are positive integers, an m x n matrix is a rectangular array of numbers with m rows and n columns. Matrix notation will simplify the calculations of a linear system.

## Elementary Row Operations

There are three elementary row operations:
* Replacement
* Interchanging
* Scaling
The following are an explanation and examples of the three different operations. In the chapter Systems of Linear Equations we have used all of these operations, except Scaling.
An important thing to remember is that all operations can be used on all matrices, not just on matrices derived from linear systems.

### Replacement

Replace one row by the sum of itself and a multiple of another row. A more common paraphrase of row replacement is "Add to one row a multiple of another row."
An example is, we are given the linear system:
    $x_{1}+4x_{2}=3$
    $2x_{1}+2x_{2}=4$
Which can be written in matrix notation, as an augmented matrix, like this
    ${\begin{bmatrix}1&&4&&3\\2&&2&&4\end{bmatrix}}$
Now we have decided to eliminate the $x_{1}$ term in equation 2, this can be done by adding -2 times equation 1 to equation 2
    ${\begin{matrix}-2*[equation\ 1]:&-2x_{1}-8x_{2}=-6\\{\underline {+[equation\ 2]:}}&{\underline {2x_{1}+2x_{2}=4}}\\\left[new\ equation\ 2\right]:&-6x_{2}=-2\end{matrix}}$
Which gives us the matrix
    ${\begin{bmatrix}1&&4&&3\\0&&-6&&-2\end{bmatrix}}$

### Interchanging

Interchange two rows.
An example is, we are given the matrix
    ${\begin{bmatrix}1&&2&&3\\2&&3&&1\end{bmatrix}}$
Here we have performed an interchange operation on the two rows
    ${\begin{bmatrix}2&&3&&1\\1&&2&&3\end{bmatrix}}$
This is a useful operation when you are trying to solve a linear system, and can see that it will be easier to solve it by interchanging two rows. It is a widely used operation, even though it seems odd and not very usable.

### Scaling

Multiply all entries in a row by a nonzero constant.
An example is, we are given the matrix
    ${\begin{bmatrix}1&&2&&3\\2&&3&&1\end{bmatrix}}$
Now a scaling operation has been performed on the first row, by multiplying by -2
    ${\begin{bmatrix}-2&&-4&&-6\\2&&3&&1\end{bmatrix}}$

## Solving a Linear System

The basic strategy for solving a linear systems is to replace one system with an equivalent system (i.e. another system with the same solution set) that is easier to solve. This is done by using $x_{1}$ term from the first equation to eliminate the $x_{1}$ terms in the other equations, use the $x_{2}$ term from the second equation to eliminate the $x_{2}$ terms in the other equations, and so forth, until you get a very simple equivalent system of equations. There are three operations that are used to simplify a system. You can replace one equation by the sum of itself and a multiple of another equation, we can interchange two equations, and multiply all the terms in an equation with a nonzero constant. During this example, we can see why these operations do not change the solution set of a system.
Example 1: Solve this linear system
    $x_{1}-2x_{2}+x_{3}=0$
    $2x_{2}-8x_{3}=8$
    $-4x_{1}+5x_{2}+9x_{3}=-9$
The augmented matrix for this system is
    ${\begin{bmatrix}1&&-2&&1&&0\\0&&2&&-8&&8\\-4&&5&&9&&-9\end{bmatrix}}$
The first thing we want is keep $x_{1}$ in the first equation and eliminate it from the other equations.
To achieve this, we add 4 times equation 1 to equation 3.
    ${\begin{matrix}4*[equation\ 1]:&4x_{1}-8x_{2}+4x_{3}=0\\{\underline {+[equation\ 3]:}}&{\underline {-4x_{1}+5x_{2}+9x_{3}=-9}}\\\left[new\ equation\ 3\right]:&-3x_{2}+13x_{3}=-9\end{matrix}}$
The result of this calculation is written in place of the original equation 3
    ${\begin{matrix}x_{1}-2x_{2}+x_{3}=0\\2x_{2}-8x_{3}=8\\-3x_{2}+13x_{3}=-9\end{matrix}}\qquad {\begin{bmatrix}1&&-2&&1&&0\\0&&2&&-8&&8\\0&&-3&&13&&-9\end{bmatrix}}$
Next thing we want to do is to multiply equation 2 with ${\frac {1}{2}}$ to obtain 1 as the coefficient for $x_{2}$, which will simplify arithmetic in the next step
    ${\begin{matrix}x_{1}-2x_{2}+x_{3}=0\\x_{2}-4x_{3}=4\\-3x_{2}+13x_{3}=-9\end{matrix}}\qquad {\begin{bmatrix}1&&-2&&1&&0\\0&&1&&-4&&4\\0&&-3&&13&&-9\end{bmatrix}}$
Now, we use $x_{2}$ in equation 2 to eliminate the $-3x_{2}$ in equation 3
    ${\begin{matrix}3*[equation\ 2]:&3x_{2}-12x_{3}=12\\{\underline {+[equation\ 3]:}}&{\underline {-3x_{2}+13x_{3}=-9}}\\\left[new\ equation\ 3\right]:&x_{3}=3\end{matrix}}$
The new linear system has a triangular form, which is called echelon form, and looks like this
    ${\begin{matrix}x_{1}-2x_{2}+x_{3}=0\\x_{2}-4x_{3}=4\\x_{3}=3\end{matrix}}\qquad {\begin{bmatrix}1&&-2&&1&&0\\0&&1&&-4&&4\\0&&0&&1&&3\end{bmatrix}}$
The next step is to use $x_{3}$ in equation 3 to eliminate the $x_{3}$ and $-4x_{3}$ in equation 1 and 2.
    ${\begin{matrix}-1*[equation\ 3]:&-x_{3}=-3\\{\underline {+[equation\ 1]:}}&{\underline {x_{1}-2x_{2}+x_{3}=0}}\\\left[new\ equation\ 1\right]:&x_{1}-2x_{2}=-3\end{matrix}}\qquad \qquad {\begin{matrix}4*[equation\ 3]:&4x_{3}=12\\{\underline {+[equation\ 2]:}}&{\underline {x_{2}-4x_{3}=4}}\\\left[new\ equation\ 2\right]:&x_{2}=16\end{matrix}}$
The system now looks like this
    ${\begin{matrix}x_{1}-2x_{2}=-3\\x_{2}=16\\x_{3}=3\end{matrix}}\qquad {\begin{bmatrix}1&&-2&&0&&-3\\0&&1&&0&&16\\0&&0&&1&&3\end{bmatrix}}$
Now we are just one step away from obtaining the solution of the linear system. The last step is to add 2 times equation 2 to equation 1. When doing so we obtain the linear system, which has a reduced echelon form
    ${\begin{matrix}x_{1}=29\\x_{2}=16\\x_{3}=3\end{matrix}}\qquad {\begin{bmatrix}1&&0&&0&&29\\0&&1&&0&&16\\0&&0&&1&&3\end{bmatrix}}$
Now that the linear system is solved, it shows that the only solution of the original system is $(29,16,3)$. However, because of the many calculations involved, it is a good practice to check you work. This is done by substituting the solution into the original system
    $(29)-2(16)+(3)=29-32+3=0$
    $2(16)-8(3)=32-24=8$
    $-4(29)+5(16)+9(3)=-116+80+27=-9$
This shows us that the solution we found is right, and therefore is a solution of the original linear system.

## References

* ↑ Onan, Linear Algebra