1703 Lecture: Introduction to Matlab
Matrix Representation
 
Can someone give me some values of x and y that satisfy this equation?
| x | y | 
| 3 | 1 | 
| 1 | 0 | 
| 2 |   | 
| 101 | 50 | 
How many combinations of x and y will satisfy this equation?  
How else can we represent this equation?
As a line:
(insert figure here)
Is the slope positive or negative? 
What's the slope?
 
Some values of x and y that satisfy this equation?
How many combinations of x and y will satisfy this equation?  
We can also represent this equation as a line
(insert figure here - both lines on same plot)
What's the slope?
We can see that the point x=3, y=1 is where these two lines meet - which means it is the combination of x and y that satisfies both of these equations.
How else can we represent these equations?
In column form:
![{\displaystyle \left[{\begin{array}{cc}1\\3\end{array}}\right]x+\left[{\begin{array}{cc}-2\\2\end{array}}\right]y=\left[{\begin{array}{cc}1\\11\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/a613336c9ea9c3b10d6dacb60c1cc9680805e76c) 
After pushing these two columns together, we get:
![{\displaystyle \left[{\begin{array}{cc}1&-2\\3&2\end{array}}\right]\left[{\begin{array}{c}x\\y\end{array}}\right]=\left[{\begin{array}{c}1\\11\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/bd52e10072483f7f2c6350935ab7ca9e351cb9e3) 
What about the equations:
 
How to represent this graphically?
Instead of lines, use planes
Let's look at the first 2 equations only:
(Insert figure here)
The two planes intersect to form a line
Now the third equation: Also a plane
The line that represents the intersection of these first two equations will intersect the third equation's plane at one point
We can also represent these equations in matrix form:
![{\displaystyle \left[{\begin{array}{cc}3\\2\\1\end{array}}\right]x+\left[{\begin{array}{cc}5\\-1\\4\end{array}}\right]y+\left[{\begin{array}{cc}1\\-1\\-2\end{array}}\right]z=\left[{\begin{array}{cc}16\\3\\3\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/058afe0ad355385751759f5a7122bd22d7cb7f7c) 
![{\displaystyle \left[{\begin{array}{ccc}3&5&1\\2&-1&-1\\1&4&-2\end{array}}\right]\left[{\begin{array}{c}x\\y\\z\end{array}}\right]=\left[{\begin{array}{c}16\\3\\3\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/0073f0877eff3b2cc9644428c4dbfee6ed7c5de3) 
How do we represent 4 equations graphically?
5 equations?
6 equations?
We run into a limit using graphical methods
What about the matrix representation of 4 equations?  5 equations?  6 equations?
The matrix representation is easy and flexible
Solving Systems of Equations
Now let's talk about how you actually solve these systems...
Going back to original example:
 
or,
![{\displaystyle \left[{\begin{array}{cc}1&-2\\3&2\end{array}}\right]\left[{\begin{array}{c}x\\y\end{array}}\right]=\left[{\begin{array}{c}1\\11\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/bd52e10072483f7f2c6350935ab7ca9e351cb9e3) 
Option A:
Use elimination to eliminate one variable, solve for the other variable
Then plug that into one of these equations to find the other variable
Example:
Eliminate y by adding the two equations:
 
and therefore
 
Then solve for y by plugging  into original equations:
 into original equations:
 
Let's see what's happening in matrix form:
![{\displaystyle \left[{\begin{array}{cc}1&-2\\3&2\end{array}}\right]\left[{\begin{array}{c}x\\y\end{array}}\right]=\left[{\begin{array}{c}1\\11\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/bd52e10072483f7f2c6350935ab7ca9e351cb9e3) 
We're adding equation (1) to equation (2), and using that as our new equation (2) 
So in the matrix, we're replacing row(2) with ( row(1) + row(2) )
The matrix becomes:
![{\displaystyle \left[{\begin{array}{cc}1&-2\\4&0\end{array}}\right]\left[{\begin{array}{c}x\\y\end{array}}\right]=\left[{\begin{array}{c}1\\12\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/f66c53f9e6d1732ccfb2cd3e3140ce432393e58f) 
Option B:
What's another way we can solve this?
(Cramer's Rule homework assignment)
Cramer's Rule:
If we have a system like:
![{\displaystyle \left[{\begin{array}{cc}a&b\\c&d\end{array}}\right]\left[{\begin{array}{c}x\\y\end{array}}\right]=\left[{\begin{array}{c}e\\f\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/245dd1fcade9c18b1250cb46b3eb8a7be364eba1) 
then the solution is:
 
and for y:
 
One more 2x2 example:
 
or,
![{\displaystyle \left[{\begin{array}{cc}2&4\\-3&-2\end{array}}\right]\left[{\begin{array}{c}x\\y\end{array}}\right]=\left[{\begin{array}{c}1\\3\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/f792a4ad6b5b0edf4e50dccbd64771296aea37f5) 
Let's try eliminating x or y and then solving for the remaining variable
So try (1) + 2*(2):
 
and solving for x,
 
Then we can plug this into our remaining equation and solve for y:
 
 
Look at what we did with our matrix:
We changed row (2) to be row (1) + 2*row(2)
(Can you tell me what I should change in my matrix?)
![{\displaystyle \left[{\begin{array}{cc}2&4\\-3&-2\end{array}}\right]\rightarrow \left[{\begin{array}{cc}2&4\\-4&0\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/8f99a9b3a9d46d5ff98e258088e5dc0e4398cfa2) 
Now an example for a 3x3 system:
 
or,
![{\displaystyle \left[{\begin{array}{ccc}1&3&-1\\-2&-6&1\\3&5&-2\end{array}}\right]\left[{\begin{array}{c}x\\y\\z\end{array}}\right]=\left[{\begin{array}{c}1\\-3\\4\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/0340b75a5276b6c645ff1707c7e2b1f0515271d7) 
Using elimination: First, we want 1 equation with 1 unknown
Try eqn (3) + eqn (2) - eqn (1)
 
so,
 
Next, we want an equation with two unknowns: y, and something else
Let's try (3) + 2*(2):
 
Next when we plug in  we get
 we get
 
Finally, we want an equation with all 3 unknowns, so that we can plug in the values for x and y that we just found
 
so,
 
What happened to our matrix?  What did our matrix become?
Did row 1 change?
Did row 2 change?
For the first step, we transformed row (3) into row(3) + row(2) - row(1)
![{\displaystyle \left[{\begin{array}{ccc}1&3&-1\\-2&-6&1\\3&5&-2\end{array}}\right]\rightarrow \left[{\begin{array}{ccc}1&3&-1\\-2&-6&1\\0&-4&0\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/6c2dde0cc9909d0a00ca9209ac962a34bc047dce) 
What happened in the second step?
Row(2) changed to row(3) + 2*row(2)
![{\displaystyle \left[{\begin{array}{ccc}1&3&-1\\-2&-6&1\\0&-4&0\end{array}}\right]\rightarrow \left[{\begin{array}{ccc}1&3&-1\\-1&-7&0\\0&-4&0\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/faa8a98c614ebd1a984b6015bf52b4e45714951a) 
or, we could swap column 1 and column 2 and rewrite this as:
![{\displaystyle \left[{\begin{array}{ccc}3&1&-1\\-7&-1&0\\-4&0&0\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/ae801a091ee4a87bb16d34d08ba0db565c143c54) 
If we swapped column 1 and column 2, how would we have to change the unknowns vector?
![{\displaystyle \left[{\begin{array}{c}x\\y\\z\end{array}}\right]\rightarrow \left[{\begin{array}{c}y\\x\\z\end{array}}\right]}](https://en.wikipedia.org/api/rest_v1/media/math/render/svg/65e3e4a1adbc92bf00f0d882b67c23f59fa059c9)