Sale!

SOLVED: Math 551 Lab 8

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (3 votes)

Tasks
1. Open the file m551lab08.m in the Matlab editor. Move to the cell titled “Part 1” and run it. Matlab
should open a figure window that looks like the following.
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
Spend some time getting to know this figure. On the left, you see a representation of some vectors in
R
2
. The red and blue vectors are the vectors
e1 =

1
0

and e2 =

0
1

respectively. These two vectors define a very natural grid in the plane made up of two types of lines
(shown in gray). First, there are lines that run parallel to the blue vector and are spaced apart by a
length determined by the red vector. Second, there are lines that run parallel to the red vector and
are spaced apart by a length determined by the blue vector. These lines intersect at points of the form
ke1 + `e2 where k and ` are both integers. By looking at the grid lines, you can see that the magenta
vector is x = e1 + 3e2.
Now, look at the plot on the right. Understanding this plot will help you visualize the behavior of the
matrix
A =

1 −1
−2 −1

.
First, spend some time convincing yourself that the red and blue vectors on the right are exactly Ae1
and Ae2. Next, take a look at the thin gray lines. Although they are no longer horizontal and vertical,
these lines still have the interpretation from before. There are lines parallel to red spaced by blue, and
lines parallel to blue spaced by red. Think of the lines as city streets. In the left plot, the endpoint of
the magenta vector x can be located by following the directions “Go one block in the red direction and
three blocks in the blue direction.” And in the right plot, the magenta vector Ax can be described in
exactly the same way! This is a geometric way of visualizing the fact that
Ax = A(1e1 + 3e2) = 1(Ae1) + 3(Ae2).
2. Now, you’ll use these ideas to solve a linear system. Notice that there is a gray vector drawn in the
right plot of the figure above. This is your target vector b defined in the M-file as
% define the target vector
b = [ 2.5; 1 ];
2
Your task is to change the definition of x part1 at the top of the cell until the magenta vector is
identical to the gray vector. You can do this by trial and error, but you’ll be much more efficient if you
spend a little time counting the “city blocks”. As a hint, notice that you need to go in the opposite
direction of the blue vector, but in the same direction as the red. So your blue component should be
negative and your red component positive.
When you run the cell, notice that the script produces some output in the command window. With
the original value of x part1, the output is
Part 1: error in Ax-b = 7.500000e+00
You’ll know that you’re finished when you get the error to 0. (Yes, in this case, you can actually get
0 error.)
Variables: x part1
3. Now move to the cell labeled “Part 2” and run it. This cell behaves very much like the previous, except
for two changes. First, I have changed the definition of A to
A =

1 −0.25
−2 0.5

.
Second, I have added another vector (green) to the plots. Now, Matlab produces a figure that looks
like the following.
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
To convince yourself that the the plot makes sense, you should verify that the vectors Ae1 and Ae2
both lie on the same line through the origin. That means that the “streets” in the blue direction are
exactly the same as those in the red direction. In fact, there’s only one street in the transformed city.
Note that, again, the target vector b is drawn in gray. Locate the appropriate place at the very top of
the M-file cell and answer the following question.
Q1: Why can’t there exist a solution to the system Ax = b in this case?
4. Now, let’s figure out a system we can solve. Near the top of the cell, locate the definition of the variable
b part2. Change this definition so that
(a) a solution does exist, and
(b) the first component of b is 2.
Again, you can probably find the right vector by trial and error, but it might pay to think for a bit
about what line b lies on.
Once you have found the right-hand side b, move a few lines up in the M-file to where x1 part2 and
x2 part2 are defined. These lines define vectors x1 and x2 (magenta and green, respectively). Your
next task is to modify their definitions so that
3
(a) both are solutions to the linear system with your new b,
(b) the second component of x1 is 0, and
(c) the first component of x2 is 0.
The code in the cell will provide feedback on your progress. You’ll know you’re finished when no
warnings are reported and when both errors are exactly 0.
Variables: b part2, x1 part2, x2 part2
5. In the final part of this lab, let’s return to the original matrix A and ask a different question. Move to
“Part 3” in the M-file and run the cell. Matlab should produce the following figure.
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
We’re basically back to where we started in Part 1, but now, instead of a fixed b, we’re going to have
a moving target. More specifically, the magenta vector in the left plot is a vector x defined in the
variable x part3, and the magenta vector on the right is Ax. However, this time the gray vector on
the right is simply x again. Your task is to find a vector x so that, on the right, the gray vector (x)
and the magenta vector (Ax) lie on the same line. (Such a vector is called an eigenvector of A.)
To see that such a thing is possible, find the following code in this cell.
% define the vector x
x_part3 = [ 1; 1 ]; % first figure
%x_part3 = [ 0.732050807568877; 2.0 ]; % second figure
Switch the comment character (%) from the last line to the one above, so that the code looks like this.
% define the vector x
%x_part3 = [ 1; 1 ]; % first figure
x_part3 = [ 0.732050807568877; 2.0 ]; % second figure
Run the cell again and Matlab should produce the following picture.
4 Math 551
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
Although it might not be easy to tell for sure just by looking at the plot, the gray and magenta vectors
do lie on the same line. In fact, Ax = −

3x. To check this, enter the following into Matlab’s command
window.
>> A*x_part3 + sqrt(3)*x_part3
ans =
1.0e-15 *
-0.8882
0.4441
This shows that the difference between Ax and −

3x is 0 plus some roundoff errors.
Your final task in this lab is to find another eigenvector of A, this time with Ax = +√
3x. The
particular x you are seeking has 2 as its second component and points into the second quadrant (the
first component is negative). If you’ve learned about eigenvalues already, you may know how to find
this vector using Matlab functions. If not, or if you’re interested in developing your geometric intuition,
use trial and error. Since you know that the second component should be 2 and the first component
should be negative, it won’t take too long. You’ll know you’re finished when the code produces no
warnings and when your error is less than 10−2
. Using only 3 digits for x:
x_part3 = [ -?.??; 2 ];
I was able to get the output to look like this:
************************************************************
* Part 3
************************************************************
error in current guess = 4.367738e-03
************************************************************
(If you want more of a challenge, try to get the error below 10−3
. I got an error just below that using
5 digits.)
Variables: x part3
5 Math 551