






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Homework # 1
Guidelines : Please turn in a neat homework that gives all the formulae that you have used and all the necessary information for the grader to understand your solution. Also, if the problem requires you to write a MATLAB code, please turn in, along with the written explanation of your solution, (i) a copy of the code you used, carefully documented with comments and using proper indentation, and (ii) the requested ouputs and graphs.
Problem 1 – 4 points
. (Remember that λ is an eigen-
value of A if | A − λ I | = 0 with I the identity matrix – Hint: one of the eigenvalue is equal to 1). For each of the eigenvalues compute an associated eigenvector.
Solution: We first find the eigenvalues
0 = | A − λ I | =
−λ − 1 − 1 − 2 1 − λ − 2 1 − 1 2 − λ
= (−λ)
− 3 λ + λ^2
Which is the same as 0 = λ^3 − 3 λ^2 − λ + 3 = (λ + 1 )(λ − 1 )(λ − 3 ) ⇒ λ = − 1 , 1 , 3 We can now find associated eigenvectors λ = − 1 :
A x = x λ ⇒
− y − z = − x − 2 x + y − 2 z = − y x − y + 2 z = − z
x − y − z = 0 − 2 x + 2 y − 2 z = 0 x − y + 3 z = 0
x = 1 y = 1 z = 0
⇒ x =
λ = 1 :
A x = x λ ⇒
− y − z = x − 2 x + y − 2 z = y x − y + 2 z = z
− x − y − z = 0 − 2 x − 2 z = 0 x − y + z = 0
x = 1 y = 0 z = − 1
⇒ x =
λ = 3 :
A x = x λ ⇒
− y − z = 3 x − 2 x + y − 2 z = 3 y x − y + 2 z = 3 z
− 3 x − y − z = 0 − 2 x − 2 y − 2 z = 0 x − y − z = 0
x = 0 y = 1 z = − 1
⇒ x =
Solution: Note that MATLAB code will be identified with the font: MATLAB code will have this font!
% Eigenvalue/vector script for MAE 107 HW problem 1. A = [0 -1 -1 ; -2 1 -2 ; 1 -1 2] [V,D]=eig(A)
Witht the output
We note here that eigenvectors are not unique, hence the difference between the columns of the MATLAB solution and the analytic solutions found above. It is, however, important to note that the eigenvector x satisfies the equation A x = λ x where x 6 = 0 which holds true for the analytic and numerical soltuions.
Problem 2 – 7 points
(adapted from Chapra – Exercise 3.13)
The “divide and average” method, an old-time method for approximating the square root of any positive number a , can be formulated as
xn + 1 = xn + a / xn 2
(^00 1 2 3 4 5 6 7 8 9 )
200
400
600
800
1000
1200
1400
1600
Convergence of Square Root Estimation Algorithma = 8465 and x0 = 1600 Actual value sqrt(a) = 92.
Number of iterations (n)
Estimated Value
(^00 1 2 3 4 5 6 7 8 9 )
2
4
6
8
10
12
14
16
18 a = 8465 and x0 = 1600^ True Relative Error
Numer of iterations (n)
True Relative Error
Figure 1: Conversion alaysis for
% Points for data arrays x = zeros(1,N+1); e = zeros(1,N+1);
% Initialize the first point to be our initial guess with the associated % true relative error x(1,1) = x0; e(1,1) = abs(sqrt(a) - x0)/sqrt(a);
% For loop to iterate N steps with the divide algorithm % Iterated data fields of values (x_temp) and error (e_temp) are stored in % the vectors x and e respectivly for plotting for steps = 1:N [x_temp, e_temp] = divide(a,x0,steps); x(1,steps+1) = x_temp; e(1,steps+1) = e_temp; end
% Plots of convergence and error figure(1) subplot(2,1,1) plot([0:N],x,’k’) title({[’Convergence of Square Root Estimation Algorithm’];[’a = ’, num2str(a), ’ and x0 = ’,n xlabel(’Number of iterations (n)’)
ylabel(’Estimated Value’) subplot(2,1,2) plot([0:N],e,’r’) title({[’True Relative Error’];[’a = ’, num2str(a), ’ and x0 = ’,num2str(x0)]}) xlabel(’Number of iterations (n)’) ylabel(’True Relative Error’)
Solution: Proof (by induction):
− Assume x 0 > 0 (note a > 0!) − Assume that xi > 0 for i > 0, and prove that it implies that xi + 1 > 0 xi + 1 = xi +^ xia 2 ⇒^2 xi +^1 =^ xi^ +^
a xi xi > 0 by assumtion and ⇒ a xi > 0 because a > 0 Therefore 2 xi + 1 > 0 ⇒ xi + 1 > 0
− x 0 > 0, and xi > 0 ⇒ xi + 1 > 0 for all i > 0, therefore xi > 0 for all values of i ≥ 0
Note that the same proof holds for x 0 < 0. Therefore, xi has the same sign as x 0.
We can prove this with the algorithm by noting:
% check divide.m sign script % Initialization value N = 10; a = 8465; x0 = 1600;
[xp,e] = divide(a,x0,N) [xn,e] = divide(a,-x0,N)
And noting the sign of the results for x: i.e. xn is negative and xp is positive relative to the sign of x 0!
xp =
e =
x_prev = x0; x0 = (1/2)*(x0 + (a/x0)); a_r_e = abs((x0 - x_prev)/x0); counter = counter + 1; if (a_r_e > 1e-10) break end end
% Display the number of iterations disp([’Needed ’, num2str(counter), ’ iterations for convergence’])
Solution:
[x0,a_r_e,counter] = divide2(2,2) Needed 5 iterations for convergence
x0 =
a_r_e =
1.1278e-
counter =
5
[x0, a_r_e, counter]=divide2(2,20) Needed 9 iterations for convergence
x0 =
a_r_e =
4.7103e-
counter =
9
You can observe that this method is very efficient: with only five iterations, the value of
2 was found with more than ten significant digits accurate. The number of iterations is reduced if the initial guess is close from the correct value.
Problem 3 – 3 points
(from Chapra – Exercise 4.8)
(3-digit arithmetic with chopping: after each elementary operation is performed, the result is approximated by the nearest number with 3 significant digits. Example: a = 1 .71 and b = 9 .76; if computed exactly, ab = 16 .6896. In 3-digit arithmetic with chopping, ab is approximated as 16.7.) Solution:
y = ( x ) ( x ) ( x ) − 7 ( x ) ( x ) + 8 ( x ) ( x ) − 0. 35 = ( 1. 88 ) ( 1. 37 ) − 7 ( 1. 88 ) + 8 ( 1. 37 ) − 0. 35 = 2. 58 − 13. 2 + 11. 0 − 0. 35 = − 10. 6 + 11. 0 − 0. 35 = 0. 40 − 0. 35 = 0. 05
Absolute error = | 0. 043053 − 0. 05 | = 0. 006947 Relative error = 0.^0430530. 043053 −^0. 05 = 0 .1614 or 16.14%
3.14 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7
3.154^ Convergence of^ π−Estimation Algorithm
Number of iterations 10x
Estimated Value
Figure 2: Convergence π estimation algorithm
The variation of the true relative error with N is shown on Figure 3 in logarithmic axes. The curve is observed to be a straight line. Since both axes are logarithmic, this means that log ε ∼ α log N + β or equivalently ε ∼ AN α. Comparing with the curve corresponding to 1/ N , we observe that they are parallel and therefore have the same slope α = −1. This shows that ε ∼ A / N and the error decreases like 1/ N as N gets large.
101 102 103 104 105 106 107
10 −
10 −
10 −
10 −
10 −
10 −
10 −
10 −
Error 1/N
Figure 3: True Relative Error for π estimation algorithm