Introduction to Matlab
From charlesreid1
Contents
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? Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \infty}
How else can we represent this equation?
As a line:
(insert figure here)
Is the slope positive or negative?
What's the slope?
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 3x + 2y = 11 }
Some values of x and y that satisfy this equation?
| x | y |
| 3 | 1 |
| 1 | 4 |
| 75 | -107 |
How many combinations of x and y will satisfy this equation? Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \infty}
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:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
After pushing these two columns together, we get:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
What about the equations:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} 3x + 5y + z & = & 16 \\ 2x - y - z & = & 3 \\ x + 4y - 2z &=& 3 \end{align} }
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:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
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:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} x - 2y &=& 1 \\ 3x + 2y &=& 11 \end{align} }
or,
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
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:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} x - 2y & = & 1 \\ \underline{ + \left( 3x + 2y \right) } &=& \underline{ +(11) } \\ 4x + 0y & = & 12 \end{align} }
and therefore
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle x = 3 }
Then solve for y by plugging Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle x=3} into original equations:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} x - 2y &=& 1 \\ (3) - 2y &=& 1 \\ -2y &=& -2 \\ y &=& 1 \end{align} }
Let's see what's happening in matrix form:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
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:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
Option B:
What's another way we can solve this?
(Cramer's Rule homework assignment)
Cramer's Rule:
If we have a system like:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
then the solution is:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} x &=& \frac{ed - bf}{ad - bc} = \frac{ (1)(2) - (-2)(11) }{ (1)(2) - (-2)(3) } \\ &=& \frac{2 + 22}{2 + 6} \\ x &=& 3 \end{align} }
and for y:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} y &=& \frac{af - ec}{ad - bc} = \frac{ (1)(11) - (1)(3) }{ (1)(2) - (-2)(3) } &=& \frac{11-3}{2+6} y &=& 1 \end{align} }
One more 2x2 example:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} 2x + 4y &=& 1 \\ -3x - 2y &=& 3 \end{align} }
or,
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
Let's try eliminating x or y and then solving for the remaining variable
So try (1) + 2*(2):
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} 2x + 4y &=& 1 \\ \underline{ +2 \left( -3x - 2y \right) } &=& \underline{ +2 (3) } \\ -4x + 0y &=& 7 \end{align} }
and solving for x,
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle x = -\frac{7}{4} }
Then we can plug this into our remaining equation and solve for y:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} 2x + 4y &=& 1 \\ 2 \left( - \frac{7}{4} \right) + 4y &=& 1 \\ -\frac{14}{4} + 4y &=& 1 \\ 4y &=& \frac{4}{4} + \frac{14}{4} = \frac{18}{4} \\ \end{align} }
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle y = \frac{9}{8} }
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?)
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \left[ \begin{array}{cc} 2 & 4 \\ -3 & -2 \end{array} \right] \rightarrow \left[ \begin{array}{cc} 2 & 4 \\ -4 & 0 \end{array} \right] }
Now an example for a 3x3 system:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} x + 3y - z &=& 1 \\ -2x - 6y + z &=& -3 \\ 3x + 5y - 2z &=& 4 \end{align} }
or,
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
Using elimination: First, we want 1 equation with 1 unknown
Try eqn (3) + eqn (2) - eqn (1)
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} 3x + 5y - 2z &=& 4 \\ +( -2x - 6y + z ) &=& (-3) \\ \underline{ -( x + 3y - z )} &=& \underline{(1)} \\ 0x - 4y + 0z &=& 0 \\ -4y &=& 0 \end{align} }
so,
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle y = 0 }
Next, we want an equation with two unknowns: y, and something else
Let's try (3) + 2*(2):
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} 3x + 5y - 2z &=& 4 \\ \underline{ +2( -2x - 6y + z ) } &=& \underline{-3} \\ -x - 7y + 0z &=& -2 \end{align} }
Next when we plug in Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle y=0} we get
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle x = 2 }
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
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \begin{align} 3x + 5y - 2z &=& 4 \\ 3(2)+0-2z &=& 4 \\ -2z &=& -2 \end{align} }
so,
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle z = 1 }
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)
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
What happened in the second step?
Row(2) changed to row(3) + 2*row(2)
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\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] }
or, we could swap column 1 and column 2 and rewrite this as:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \left[ \begin{array}{ccc} 3 & 1 & -1 \\ -7 & -1 & 0 \\ -4 & 0 & 0 \end{array} \right] }
If we swapped column 1 and column 2, how would we have to change the unknowns vector?
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \left[ \begin{array}{c} x \\ y \\ z \end{array} \right] \rightarrow \left[ \begin{array}{c} y \\ x \\ z \end{array} \right] }