You are on page 1of 16

Table of Contents

....................................................................................................................................... 2
1. ..................................................................................................................................... 2
a. ..................................................................................................................................... 2
b. ..................................................................................................................................... 2
c. ..................................................................................................................................... 2
d. ..................................................................................................................................... 3
e. ..................................................................................................................................... 3
f. ..................................................................................................................................... 3
g. ..................................................................................................................................... 3
h. ..................................................................................................................................... 4
2. ..................................................................................................................................... 4
a. ..................................................................................................................................... 4
b. ..................................................................................................................................... 4
c. ..................................................................................................................................... 4
3. ..................................................................................................................................... 4
a. ..................................................................................................................................... 4
b. ..................................................................................................................................... 5
c. ..................................................................................................................................... 5
d. ..................................................................................................................................... 6
e. ..................................................................................................................................... 6
4. ..................................................................................................................................... 6
a. ..................................................................................................................................... 6
b. ..................................................................................................................................... 7
5. ..................................................................................................................................... 8
a. ..................................................................................................................................... 8
b. ..................................................................................................................................... 8
c. ..................................................................................................................................... 9
d. ..................................................................................................................................... 9
e. ................................................................................................................................... 10
f. .................................................................................................................................... 10
g. ................................................................................................................................... 10
h. ................................................................................................................................... 11
i. .................................................................................................................................... 11
6. ................................................................................................................................... 12
a. ................................................................................................................................... 12
b. ................................................................................................................................... 12
c. ................................................................................................................................... 13
d. ................................................................................................................................... 13
e. ................................................................................................................................... 13
f. .................................................................................................................................... 14
7. ................................................................................................................................... 14
a. ................................................................................................................................... 14
b. ................................................................................................................................... 14
c. ................................................................................................................................... 15
8. ................................................................................................................................... 15
a. ................................................................................................................................... 15
b. ................................................................................................................................... 15
c. ................................................................................................................................... 15
d. ................................................................................................................................... 16
e. ................................................................................................................................... 16

%%Peter Offenbacher
%MATLAB 4

MATH240
4/26/12

1.
clear all

a.
v1=[1 ; -3 ; 2 ; 5], v2=[3 ; 0 ; -1 ; 6], v3=[-1 ; 2 ; 7 ; 1]

v1 =
1
-3
2
5

v2 =
3
0
-1
6

v3 =
-1
2
7
1

b.
dot(v1,v2)

ans =
31

c.
norm(v3)

ans =
7.4162

d.
norm(v3-v1)

ans =
8.3666

e.
v3/norm(v3)

ans =
-0.1348
0.2697
0.9439
0.1348

f.
(dot(v2,v1)/dot(v1,v1))*v1

ans =
0.7949
-2.3846
1.5897
3.9744

g.
v4=v2-(dot(v1,v2)/dot(v1,v1))*v1

v4 =
2.2051
2.3846
-2.5897
2.0256

h.
(dot(v1,v3)/dot(v1,v1))*v1+(dot(v2,v3)/dot(v2,v2))*v2

ans =
0.0468
-0.9231
0.7023
1.0167

2.
a.

U=[3/sqrt(11) -1/sqrt(6) -1/sqrt(66) ; 1/sqrt(11) 2/sqrt(6) -4/sqrt(66) ; 1/sqrt(11

U =
0.9045
0.3015
0.3015

-0.4082
0.8165
0.4082

-0.1231
-0.4924
0.8616

0
1.0000
0

0.0000
0
1.0000

b.
(U')*U

ans =
1.0000
0
0.0000

c.
The columns of U form an orthonormal set because multiplying its tranpose by itself returns the identity
matrix.

3.
a.
v1=[-10 ; 2 ; -6 ; 16 ; 2], v2=[13 ; 1 ; 3 ; -16 ; 1], v3=[7 ; -5 ; 13 ; -2 ; -5],

v1 =
-10
2
-6
16
2

v2 =
13
1
3
-16
1

v3 =
7
-5
13
-2
-5

v4 =
-11
3
-3
5
-7

b.
v1p=v1

v1p =
-10
2
-6
16
2

c.
v2p=v2-(dot(v1,v2)/dot(v1,v1))*v1

v2p =
3
3
-3
0
3

d.
v3p=v3-(dot(v2,v3)/dot(v2,v2))*v2-(dot(v1,v3)/dot(v1,v1))*v1

v3p =
-2.5321
-4.3486
8.9541
11.5780
-4.3486

e.

v4p=v4-(dot(v3,v4)/dot(v3,v3))*v3-(dot(v2,v4)/dot(v2,v2))*v2-(dot(v1,v4)/dot(v1,v1)

v4p =
3.7646
0.5928
6.6900
-12.4400
-9.4072

4.
a.
A=[1 2 0 -1 ; 2 0 3 -2 ; 0 3 5 4 ; -1 -2 4 0]
[v,d]=eig(A)
dot(v(:,1),v(:,2))
dot(v(:,1),v(:,3))
dot(v(:,1),v(:,4))
% These values are actually zero and only appear to be different due to
% rounding error. Because the dot products are all zero, the eigenvectors
% are all orthogonal to each other.

A =
1
2
0
-1

2
0
3
-2

0
3
5
4

-1
-2
4
0

v =
-0.1054
0.6146
-0.4553
0.6356

-0.7697
0.4251
0.1026
-0.4652

-0.6295
-0.6168
-0.0284
0.4717

-0.0148
-0.2474
-0.8840
-0.3964

0
-0.7089
0
0

0
0
3.7089
0

0
0
0
7.6336

d =
-4.6336
0
0
0

ans =
1.1102e-016

ans =
1.6653e-016

ans =
-5.5511e-017

b.
B=[1 5 ; -1 7]
[v,d]=eig(B)
dot(v(:,1),v(:,2))

B =
1
-1

5
7

v =

-0.9806
-0.1961

-0.7071
-0.7071

d =
2
0

0
6

ans =
0.8321

5.
a.
A=[0.2 0.8 ; 0.7 0.3]
[v,d]=eig(A)
r=A*v(:,2)

A =
0.2000
0.7000

0.8000
0.3000

-0.7526
0.6585

-0.7071
-0.7071

v =

d =
-0.5000
0

0
1.0000

r =
-0.7071
-0.7071

b.
[v,d]=eig(A')

L=(A')*v(:,2)
l=L'

v =
-0.7071
0.7071

-0.6585
-0.7526

d =
-0.5000
0

0
1.0000

L =
-0.6585
-0.7526

l =
-0.6585

-0.7526

c.
c=l*r
P=(1/c)*r*l

c =
0.9978

P =
0.4667
0.4667

0.5333
0.5333

d.
P^2

ans =
0.4667
0.4667

0.5333
0.5333

e.
A^1
A^2
A^5
A^10
A^20

ans =
0.2000
0.7000

0.8000
0.3000

ans =
0.6000
0.3500

0.4000
0.6500

ans =
0.4500
0.4812

0.5500
0.5187

ans =
0.4672
0.4662

0.5328
0.5338

ans =
0.4667
0.4667

0.5333
0.5333

f.
The entries in B will converge to decimal values as B is raised to higher and higher values. If the column
or row entries in B summate to one, the column or row entries in B^n will summate to one.

g.
B=(1/8)*[3 1 4 ; 3 5 2 ; 2 2 2]
eig(B)
B^2
B^5

10

B^10
B^20

B =
0.3750
0.3750
0.2500

0.1250
0.6250
0.2500

0.5000
0.2500
0.2500

0.2500
0.5000
0.2500

0.3438
0.4063
0.2500

0.2910
0.4590
0.2500

0.2925
0.4575
0.2500

0.2917
0.4583
0.2500

0.2917
0.4583
0.2500

0.2917
0.4583
0.2500

0.2917
0.4583
0.2500

ans =
1.0000
-0.0000
0.2500

ans =
0.3125
0.4375
0.2500

ans =
0.2920
0.4580
0.2500

ans =
0.2917
0.4583
0.2500

ans =
0.2917
0.4583
0.2500

h.
The rank of A^n will always be 2.

i.
rank(A^60)

11

% Because A consists of decimals, multiplying A by itself creates an


% increasingly small decimal that MATLAB eventually treats as small enough to be ze

ans =
1

6.
a.
A=[1 2 0 ; 2 3 3 ; 2 3 5 ; -1 -2 4]

A =
1
2
2
-1

2
3
3
-2

0
3
5
4

b.
r1=A(1,:)
r2=A(2,:)
dot(r1,r2)
c1=A(:,1)
c2=A(:,2)
dot(c1,c2)
(A')*A

r1 =

r2 =

ans =
8

c1 =

12

1
2
2
-1

c2 =
2
3
3
-2

ans =
16

ans =
10
16
12

16
26
16

12
16
50

c.
The entries in the matrix A'A correspond to the dot product of the corresponding columns in A and rows
in A'.

d.
The entries in the matrix AA' correspond to the dot product of the corresponding rows in A and columns
in A'.

e.
B=[1 -2 1 ; 4 -3 -3.5 ; 3 4 3 ; 2 -5 2]
(B')*B

B =
1.0000
4.0000
3.0000
2.0000

-2.0000
-3.0000
4.0000
-5.0000

1.0000
-3.5000
3.0000
2.0000

ans =

13

30.0000
-12.0000
0

-12.0000
54.0000
10.5000

0
10.5000
26.2500

f.
M must be a diagonal matrix for M'M to be as well.

7.
a.
C=[1 -4 -2 ; 2 1 3 ; -1 0 5 ; 2 1 0]

C =
1
2
-1
2

-4
1
0
1

-2
3
5
0

b.
[Q,R]=qr(C,0)
P=Q

Q =
-0.3162
-0.6325
0.3162
-0.6325

0.9428
-0.2357
0.0000
-0.2357

-0.0975
-0.4637
-0.8776
0.0736

0.0000
-4.2426
0

0.3162
-2.5927
-5.5837

0.9428
-0.2357
0.0000
-0.2357

-0.0975
-0.4637
-0.8776
0.0736

R =
-3.1623
0
0

P =
-0.3162
-0.6325
0.3162
-0.6325

14

c.
(P')*P

ans =
1.0000
0.0000
0

0.0000
1.0000
0.0000

0
0.0000
1.0000

8.
a.
rank(C)

ans =
3

b.
y=[1 ; 2 ; 3 ; 4]

y =
1
2
3
4

c.
u=(R^(-1))*(Q')*y

u =
1.0602
-0.2569
0.6023

15

d.
v=(((C')*C)^(-1))*(C')*y

v =
1.0602
-0.2569
0.6023

e.
d=norm(C*u-y)

d =
2.9100

Published with MATLAB 7.13

16

You might also like