Here is a very important application of using Matrix
in Matlab: Solve Linear Equations:
Look at the following equation set:
We need to convert it into this format first:
Then you will get this:
Compare this figure to the last one, you will find out how to extract
the coefficients from the equation set and use 'Matrix Multiplication'
to represent the linear equation. Remember why we bother ourselves to
convert it in this format??? It was explained in last lecture:
computer friendly! We need to use this format to get Matlab to
calculate it for us!!!!!
Now, the question is HOW?
Let's do it.
If 'A' is the coefficient matrix, X is the variable column, b is the
constant column, then the matrix multiplication format can be
In linear Algebra, the 'Inverse' of a
matrix can be represented by A^(-1), you don't need to know how the
matrix is inversed now. You only need to know the following:
1) A^(-1) * A = I
2) I * A = A
In whcih I is:
It is making sense that I * A is still A based on the matrix
multiplication rules, for example:
Now, one more time:
A^(-1) * A = I
2) I * A = A
If we do this:
Then we can get:
x = A^(-1) * b
Which means we can solve the linear equation by A^(-1) * b.
b is given, A^(-1) is the
inverse matrix of A, in Matlab, it is: 'inv(A)'.
Just this simple, you can solve any linear equation set by 'inv(A) * b'
You have a
temperature sensor. You know the relation ship between the temperature
and the voltage output is:
need to know c1 and c2 to complete the equation so we can use this
equation to predict the temperature based on the voltage we detected.
There is a
student did the following measurement:
How can you
generalize c1 and c2 based on these measurements?
Let's plug in
these values to the equation:
To solve c1 and
c2 you only need two equations, why we list so many here?
The reason is,
the more equations you have, c1 and c2 can be more accurate or more
close to the real value.
would be redundant if the points were all exactly on a line. Since they
are real-life measurements, not ideal, so they are not on a line. If we
do this 'over-determined' matrix multiplication in Matlab, Matlab will
return the 'best' value for you... (an strong embedded function, you
won't see, but Matlab works hard to get you the best value):
Solve c1 and c2
Now, let's plot it:
V=[2:2:10]; % make an X axis, which is the voltage
T=[88.78 95.79 97.45 107.43 115.85]; % make an Y axis, which is the
plot(V,T,'*'); % plot the data points using * marks.
A=[2 1;4 1;6 1;8 1;10 1];
xx=A\TT; % Please notice that since A is not square so there is not an invert matrix for A so xx=inv(A)*T won't work.
line_vs=linspace(0,10,10); % generate a data set for X
line_ts=line_vs*xx(1)+xx(2); % calculate Y
plot(line_vs,line_ts); % plot
other homework other than these in-class problems. Publish your results
in one 'html' file and send it to email@example.com by Wednesday.