Set #2

advertisement
EGR 599 (Fall 2003)
__________________
LAST NAME, FIRST
Problem set #2
1. (3.71) Find the point of intersection (if any) for the following lines:
a. x  2y + 1 = 0
2x + 3y  7 = 0
b.
x  2y + 11 = 0
 x + 2y  13 = 0
 2 3 4
2. (3.11 ) Let A = 5 6 7


8 9 0
1
Compute the inverse of A in the following way:
a. Compute the determinant matrix B such that bij = det(Aij) and use the cofactors
b. Transpose and divide by det(A)
3. (3.191) Without typing in all the elements, use MATLAB to create a 66 matrix with 4’s on
the main diagonal and 1 on the first upper diagonal and first lower diagonal. This matrix is
called a band matrix with the form
0
0
0
 4 1 0
 1 4  1 0
0
0


0
 0 1 4 1 0
I= 

0 1 4 1 0 
0
0
0
0  1 4  1


0
0
0 1 4 
0
1
Advanced Engineering Mathematics with MATLAB, 2e by Thomas Harman
4. (3.231) Using the rank of the matrix whose rows are the vectors
[3 0 2 2];[6 42 24 54]; [21  21 0 15],
do the following:
a. Determine the number of linearly independent vectors
b. If the set of vectors is dependent, write the dependent vector in terms of the
independent ones.
Solution
>> A=[3 0 2 2;-6 42 24 54;21 -21 0 -15]
A=
3
0
2
2
-6
42
24
54
21
-21
0
-15
>> rank(A)
ans =
2  only two vectors are independent
 3
  6
 21  0 
0
 42 
 21 0 




 =    1x1 + 2x2 + 3x3 = 0
1
+ 2
+ 3 
2
 24 
 0  0
 
 

  
0
 54 
  15 0 
Consider the following equations constructed from the vectors x1, x2, and x3.
 3  6 21 
0 42  21


0 
2 24
1 = c A11 = c
c
 1   0 
  = 0
 2  
 3  0
42  21
24
3 = c A13
c
0
= 504c,
2 = c A12 = c
c
0  21
= 42c
2
0
 12 
 1 
 504 
0 42




=c
= 84c   2 = c  42 = 42c   1 
 
 


2 24
 3 
  84 
  2
[6 42 24 54] = 12 [3 0 2 2]  2 [21  21 0 15]
5. (3.271) Write an M-function that rotates the 2D vector x by  degrees. Test the function with
vectors (1, 0) and (0, 1) using  = 30o.
Solution
% P3_27.M Test function vrot
% Calls function vrot
%
x1=[1 0]'
% [1 0] rotated 30 degrees
y1=vrot(x1,30) % [1 0] rotated 30 degrees
pause
x2=[0 1]'
y2=vrot(x2,30)
function y2rot=vrot(xto_rot,theta_rot)
% CALL: y2rot=vrot(xto_rot,theta_rot)
% Rotate the vector xto_rot by the angle theta_rot
% x must be a 2 x 1 column vector, theta_rot in degrees.
theta_rot=theta_rot*pi/180;
% Convert to radians
Arot=[cos(theta_rot) -sin(theta_rot);sin(theta_rot) cos(theta_rot)];
y2rot=Arot*xto_rot;
______________________________________________________________________________
>> p3d27
x1 =
1
0
y1 =
1170/1351
1/2
x2 =
0
1
y2 =
-1/2
1170/1351
6. (P. Chapra 17.6) Use least-squares regression to fit a straight line, y = a + bx, to
x
y
2
9
3
6
4
5
7
10
8
9
9
11
5
2
5
3
(a) Along with the slope and intercept, compute the standard error of the estimate and the
correlation coefficient. Plot the data and the straight line. Assess the fit.
(b) Recompute (a), but use polynomial to fit a parabola, y = a + bx + cx2, to the data. Compare
the results with those of (a).
Solution
% Problem 2.6
x=[2 3 4 7 8 9 5 5];
y=[9 6 5 10 9 11 2 3];
n=length(x);
coef=polyfit(x,y,1);
ycal=polyval(coef,x);
S=sum((ycal-y).^2);
yave=mean(y);
Sdev=sum((y-yave).^2);
stde=sqrt(S/(n-2));
cor=sqrt(1-S/Sdev);
coef1=coef;
fprintf('y = a+bx, a = %8.5f, b = %8.5f\n',coef(2),coef(1))
fprintf('Standard error = %8.4f\n',stde)
fprintf('Correlation coefficient = %8.4f\n',cor)
coef=polyfit(x,y,2);
ycal=polyval(coef,x);
S=sum((ycal-y).^2);
yave=mean(y);
Sdev=sum((y-yave).^2);
stde=sqrt(S/(n-2));
cor=sqrt(1-S/Sdev);
fprintf('y = a+bx+cx^2, a = %8.5f, b = %8.5f, c = %8.5f\n',coef(3),coef(2),coef(1))
fprintf('Standard error = %8.4f\n',stde)
fprintf('Correlation coefficient = %8.4f\n',cor)
xmax=max(x);xmin=min(x);
x1=[xmin xmax];
y1=polyval(coef1,x1);
dx=(xmax-xmin)/50;
x2=xmin:dx:xmax;
y2=polyval(coef,x2);
plot(x,y,'o',x1,y1,x2,y2)
xlabel('x');ylabel('y')
y = a+bx, a = 3.48955, b = 0.62985
Standard error = 3.2214
Correlation coefficient = 0.4589
y = a+bx+cx^2, a = 16.02696, b = -4.80692, c = 0.48894
Standard error = 1.9254
Correlation coefficient = 0.8474
14
12
y
10
8
6
4
2
2
3
4
5
6
x
7
8
9
7. (3.351) Find the inverse and verify the result for the matrix that relates spherical and
rectangular coordinates.
 sin  cos 
Q =   sin 

cos  cos 
sin  sin 
cos 
cos  sin 
cos  
0 

 sin  
Solution
 A11c
 c
Ac =  A21
 A31c

 sin  cos 
  sin 

cos  cos 
sin  sin 
cos 
cos  sin 
c
A12
c
A22
A32
c
c
A13    sin  cos 
c
A23  = 
sin 

c
A33   cos  cos 
cos   sin  cos 
0   sin 

 sin   cos  cos 
 sin  sin 
 cos 
 cos  sin 
 cos  
0 

sin  
sin  sin 
cos 
cos  sin 
|A| =  sin2 cos2  cos2 sin2  cos2 cos2  sin2 sin2
|A| =  sin2 (cos2 + sin2)  cos2 (cos2 + sin2) =  1
sin  cos 
A-1 = Aa/|A| =  (Ac)T =  sin  sin 

 cos 
AA-1 = I
 sin 
cos 
0
cos  cos  
cos  sin  

 sin  
8. (3.371) Write MATLAB statements to determine if a matrix A is upper triangular or lower
triangular. Hint: Investigate the commands any, all, tril, and triu.
Solution
A=input(' Enter a matrix = ')
test1=any(tril(A,-1));
if any(test1)==1
disp('Matrix is not upper triangular')
else
disp('Matrix is upper triangular')
end
test2=any(triu(A,1));
if any(test2)==1
disp('Matrix is not lower triangular')
else
disp('Matrix is lower triangular')
end
Enter a matrix = [1 2 3;0 4 5;0 0 6]
A=
1 2 3
0 4 5
0 0 6
Matrix is upper triangular
Matrix is not lower triangular
>>
Enter a matrix = [1 2 3;4 5 6;7 8 9]
A=
1 2 3
4 5 6
7 8 9
Matrix is not upper triangular
Matrix is not lower triangular
>>
Enter a matrix = [1 0 0;2 3 0;4 5 6]
A=
1 0 0
2 3 0
4 5 6
Matrix is not upper triangular
Matrix is lower triangular
>
9. (3.391)
a. For an nn matrix A, how are det(2A) and det(A) related to det(A)?
b. Suppose A, B, and D are 22 matrices. Find the determinant of the of the 22 matrix
formed as
A B 
 0 D


-1
c. If B = M A M, show that det(B) = det(A)
Solution
a. det(2A) = 2n det(A)
det(A) = (-1)n det(A)
If all elements in any single row (or column) are multiplied by a scalar factor, the determinant is
multiplied by that factor.
b.
A B
= |A||D|
0 D
a11
a12
b11
b12
a21 a22
b21
b22
0
0
0
0
D =
a
d11 d12
d 21 d 22
4
j 1
A3 j = a31 A31c + a32 A32c + a33 A33c + a34 A34c
c
3j
a11 a12
D = a33 M33  a34 M34 = d11 a 21 a 22
0
D = d11 d22
a11
a12
a 21 a 22
 d12 d21
0
a11
a12
a 21 a 22
a11 a12
b12
b22  d12 a21 a22
0
0
d 22
=
c. |B| = |M-1| |A| |M| = |M-1||M||A| = |I||A| = |A|
a11
a12
a 21 a 22
b11
b21
d 21
( d11 d22  d12 d21) = |A||D|
Download