



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!




ME2016, Fall 2008, Dr. Ferri Homework Assignment 7 Due Wednesday, October 15
Problem 1. (1 point) Execute the Matlab command why 4 times and report the answers.
why The bald and not excessively bald and not excessively smart hamster obeyed a terrified and not excessively terrified hamster. why To fool the tall good and smart system manager. why The rich rich and tall and good system manager suggested it. why He wanted it that way.
Problem 2. (3 points) We seek the maximum of the function f ( ) x = x ⋅ sin( ) x , where x is in radians.
(a) Starting with x (^) L = 0 and x (^) U = 3, perform three iterations of the Golden-Section algorithm. What is the Golden-Section prediction of the location of the maximum after 3 iterations? (b) Compare your answer of part(a) to that obtained using the Matlab command fminbnd. Note that fminbnd finds the minimum rather than the maximum. Therefore, you need to create an anonymous function that is equal to the inverse of f(x). Taking the returned value from fminbnd as the true optimum , give the error Et for your answer in part (a). (c) Without actually performing additional iterations, how many iterations will be necessary to ensure that the maximum possible error between the Golden-Section optimum and the true optimum to be smaller than 10 -5^? Solution
(a) xL = 0 , xU = 3 , Δ x 0 (^) = ( xU − xL ) = 3 , d = R Δ x 0 =1.
x 1 (^) = xL + d = 1.8541, f 1 (^) = f ( x 1 ) =1. x 2 (^) = xU − d = 1.1459, f (^) 2 = f ( x 2 ) =1.
See that f(x 1 ) > f(x 2 ), so
x 1 (^) = xL + d = 2.2918, f 1 (^) = f ( x 1 ) =1. x 2 (^) = xU − d = 1.8541, f (^) 2 = f ( x 2 ) =1.
See that f(x 2 ) > f(x 1 ), so
x 1 (^) = xL + d = 1.8541, f 1 (^) = f ( x 1 ) =1. x 2 (^) = xU − d = 1.5836, f (^) 2 = f ( x 2 ) =1.
See that f(x 1 ) > f(x 2 ), so
x 1 (^) = xL + d = 2.0213, f 1 (^) = f ( x 1 ) =1. x 2 (^) = xU − d = 1.8541, f (^) 2 = f ( x 2 ) =1.
After 3 iterations, we see that f(x 1 ) > f(x 2 ), so xopt = x 1 = 2. (b)
f=@(x) x.*sin(x)
f =
@(x)x.*sin(x)
g=@(x) 1./f(x)
g =
@(x)1./f(x)
xmax=fminbnd(g,0,3)
xmax =
Et=xmax-xopt
Et =
(c) The max-possible error between xopt and x_true at any iteration is equal to (1 − R R ) n Δ x 0
Set (1 − R R ) n Δ x 0 = 10 −^5 and solve for n by taking the base-10 log of both sides:
− R R n Δ x = − = − R + n R + Δ x
n=(-5 - log10(1-R) - log10(Del_x0))/log10(R)
n =
See that 25 iterations will be necessary to guarantee an error of E (^) t < 10-
(^00) 0.5 1 1.5 2 2.5 3
1
2
x
f(x)
Thus, [A] is SDD
(b) Need to calculate each row-sum of absolute values:
Row 1: 3 + 1 = 4 Row 2: 1 + 3 + 1 = 5 Row 3: 1 + 3 + 1 = 5 Row 4: 1 + 3 + 1 = 5 Row 5: 2 + 5 = 7
The infinity norm is the largest row-sum, thus A ∞= 7
(c) Repeat part (b) for A-
Row 1: (89+34+13+5+1)/233 = 142/ Row 2: (34+102+39+15+3)/233 = 193/ Row 3: (13+39+104+40+8)/233 = 204/ Row 4: (5+15+40+105+21)/233 = 186/ Row 5: (2+6+16+42+55)/233 = 121/
Thus 0. 8755 233
∞
(d) cond ( A )= A ⋅ A −^1 =( 7 )*( 0. 8755 )= 6. 1288
» cond(A,inf)
ans = 6.
Problem 4. (3 points) Consider, again, the system of equations
5
4
3
2
1
x
x
x
x
x
By hand, perform 2 iterations of the Gauss-Seidel method. Compare your answer for x (2)^ with the “true answer” xtrue obtained using either inv(A)*B or A\B. What is the maximum percent error in the elements of x(2)^ compared with x (^) true. Solution
The equations above can be converted to the following 5 iteration equations:
x 1 (k+1)^ = (1 + x 2 (k))/
x 2 (k+1)^ = (0 + x 1 (k+1)^ + x 3 (k))/
x 3 (k+1)^ = (0 + x 2 (k+1)^ + x 4 (k))/
x 4 (k+1)^ = (0 + x 3 (k+1)^ + x 5 (k))/
x 5 (k+1)^ = (0 +2 x 4 (k+1)^ )/
Since no initial guess is suggested, try x(0)^ = 0. After 1 iteration, we get:
x(1)^ = [1/3 1/9 1/27 1/81 2/405 ]T
After 2 iterations, we get
x(2)^ = [10/27 11/81 4/81 22/1215 44/6075 ]T
or
x(2)^ = [0.37037 0.13580 0.049383 0.018107 0.0072428 ]T
From direct solution, we get
» x_true = A\B
x_true =
The errors are found to be:
» e = 100*(x_true-x)./x_true
e =