ALA K+Kf+Bt, part a, fall 2002
Program
1. Create the 2 x 2 matrix A with entries A(1, 1) = 1, A(1, 2) = 2,
A(2, 1) = 3 and A(2, 2) = 4.
2. Define vectors e1 = [1; 0] and e2 = [0; 1]. Compute A*e1 and Ae2.
Explain why A*e1 equals the first column of A, and A*e2 the
second.
3. Compute, using your "head computer", possibly supported
by pen and paper, the product A*v with v = [1; -2]. Then check
your answer using matlab.
4. Does the equation Ax = b have a (unique) solution (vector)
x = [x1; x2] for any given vector b = [b1; b2] ? Motivate your answer.
Hint: recall a lecture about a_1 x a_2 being nonzero.
5. Find (using pen and paper calculation) the solution of Ax = b
with b = [6; 10]. Then check your answer by computing A*x using
matlab.
6. Note that Ax in 5 equals Av in 3 scaled by the factor -2.
Is their a corresponding relation between x and v ? Is this a
coincidence or not? Hint: recall a lecture about f(x) = Ax being linear.
7. With A and b as in 5, compute A \ b (the famous matlab
"backslash"). What do you get? (hint: compair to x in 5)
8. Now define the matrix C = [1 2; 3 6]. Seek x such that
Cx = d with a) d = [2; 3] b) d = [1.5; 4.5]. Conclusions? How does matlab
handle these equations, using C \ d ?
9. Compute AC. Compare with matlab. Is A*C = C*A ? Again, check
with matlab?
10. Create the 2 x 3 - matrix B with entries B(i, j) = 2 * i - j in row
i and column j. Compute AB and try to compute BA. Conclusions?
11. Create the matrix D = [A; C]. Then check size(D), size(D, 1)
and size(D, 2). If you are uncertain about the interpretation,
consult help size. What is the size of DB ? Check by computing
D*B!
12. Compute A', B', D' and D''. A' is called the transpose of
A. How is A' denoted in AMB&S?
Check if [1 2] == [1, 2]. Check if [1 2] == [1; 2]. Check if
[1 2] == [1; 2]'.
13. Try the special commands zeros(m, n) and ones(m, n) with m = 2
and n = 3, say.
Define F(2, 3) = 7. What is F(i, j) for other combinations of i
and j than (2, 3) ?
Also, try eye(n), with n = 2 and 3 say. Define
I = eye(2).
14. Seek a matrix X such that AX = I. First try the following
method. Given A as before, define
X = [A(2, 2) - A(1, 2); -A(2, 1) A(1, 1)] / (A(1, 1)*A(2, 2) - A(1, 2)*A(2, 1)).
Check that A*X = I by computing A*X. Check if also X*A = I. What
is the matrix X called, and how is it denoted in this case?
15. Compute Y = A \ I and compare to X.
16. Solve A*x1 = e1 and A*x2 = e2 and define Z = [x1 x2]. How does
Z compare to X and Y ? Do you see why ?
17. Define vectors a = [1 2 3] and b = [4 5 6]. Compute the vector
product a x b = [ a(2)*b(3) - a(3)*b(2), a(3)*...
18. Compare the result in 17 to writing cross(a, b). Compare
cross(a, b) to cross(b, a).
19. Compute the scalar product a.b of a and b, first as
a(1)*b(1)+.. , then as sum(a.*b), then as a*b', then as dot(a, b).
Make sure you understand how each of these alternatives work.
20. Compute the projection of a onto b, and the projection of
b onto a, respectively.
21. What is the area of the triangle with vertices in the origin
and in (2, 1) and in (-2, 3) ? Check your answer is reasonable by
drawing a figure and estimating the area.
22. What is the length |v| of the vector v = [-3 4] ? Compute both
by pen and paper and using matlab. Recall that |v| = sqrt(v*v').
Also, compare to norm(v). What does length(v) give in matlab?
Check help length (and recall size).
23. What is the angle between the vectors a) v and
w = [8 6] b) v and u = [2 1] ? (hint: v.w = |v| |w| cos(x) so that
cos(x) = v.w / (|v| |w|). In b) you may solve this equation using
your Bisection solver, or check out help acos.
24. Try the following matlab function for drawing a vector a =
(a(1), a(2)).
function arrow(a)
n = [ -a(2) a(1)];
X = [ 0 a(1) .9*a(1)+.05*n(1) a(1) .9*a(1)-.05*n(1)];
Y = [ 0 a(2) .9*a(2)+.05*n(2) a(2) .9*a(2)-.05*n(2)];
line(X, Y)
set(gca, 'XLim', [-1 1]*max(abs(X)), 'YLim', [-1 1]*max(abs(Y)))
axis('equal')
Save as arrow.m. Then try it out for different vectors a, for
example arrow([2 1]) and then arrow([-1 2]). What do you then
see?
25. Maybee you then want to make a vector move around, for example
by a matlab function of the form
function CounterClock()
figure(1)
set(gcf, 'DoubleBuffer', 'on')
for v = 0 : .1 : 10
a = [cos(v) sin(v)];
arrow(a)
set(gca, 'XLim', [-2 2], 'YLim', [-2 2])
drawnow
cla
end
/Kenneth
Last modified: