This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Mathematics of Engineering  ME17 Spring 2007 Homework #4  Solutions 1. (10 points total) (a) (3 pts) To compute the first three terms for the Taylor series of f (x) = sin(x) about the point x = /4, consider the general equation for a Taylor series about the point a f (x) = f (a) + f (a)(x  a) + f (a) (x  a)2 + . 2! (1) Substituting f (x) = sin(x) and a = /4 into (1) we obtain f (x) = sin + cos 4 4 x 1  sin 4 2 4 x 4
2 + . Simplifying and only keeping the first three terms we get 2 2 2 f (x) = + x  x 2 2 4 4 4 2 . (2) (b) (3 pts) For this problem, we need to plot f (x), f0 (x), f1 (x), and f2 (x), which are given by f (x) = sin(x), 2 , f0 (x) = 2 2 2 f1 (x) = + x , 2 2 4 2 2 2 + x  x f2 (x) = 2 2 4 4 4 (3) (4) (5)
2 . (6) The m.file and corresponding plot showing all four functions are given below. 1 % % % Problem 1( b ) % % % x = 0 : 0.1 : 2; f = sin ( x ) ; f 0 = sqrt ( 2 ) / 2 + ( x  x ) ; % The ( xx ) term i s added h e r e t o make f 0 a v e c t o r f 1 = f 0 + sqrt ( 2 ) / 2 ( x  pi / 4 ) ; f 2 = f 1  sqrt ( 2 ) / 4 ( x  pi / 4 ) . ^ 2 ; hold on ; plot ( x , f ) plot ( x , f 0 , ' ' ) plot ( x , f 1 , ' . ' ) plot ( x , f 2 , ' : ' ) % Holds c u r r e n t p l o t xlabel ( ' x ' ) ; legend ( ' f ( x ) ' , ' f 0 ( x ) ' , ' f 1 ( x ) ' , ' f 2 ( x ) ' ) ; t i t l e ( ' T a y l o r S e r i e s Length Comparison ' ) ; Taylor Series Length Comparison 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0 0.2 0 0.5 1 x 1.5 2 f(x) f0(x) f1(x) f2(x) Figure 1: Problem 1b. 2 (c) (2 pts) Here we solve f1 (x) = 0 for x which gives an approximation for where f (x) = 0. f1 (x) = sin 0 = 0 = x = x = + cos 4 sin + cos 4 1+ x 4 1 4 0.2146. 4 4 4 x 4 x (7) (8) (d) (2 pts) Solving for f2 (x) = 0 we obtain f2 (x) = sin 1 + cos x  sin 4 4 4 2 1 + cos x  sin 0 = sin 4 4 4 2 1 2 0 = 1 x  x 4 2 4 1 2 2 0 = x +  1 x+ + 1 2 4 32 4 4 4 4 x 4 x
2 (9)
2 (10) Using the quadratic formula, where x= and from (10) 1 a= , 2 b=  1 , 4 c= 2 + 1 , 32 4 b b2  4ac , 2a (11) we get two approximate roots for f (x) xa = 0.0533 xb = 3.5174. (12) Here we see that xa = 0.0533 is closer to the real solution x = 0 of f (x) than the answer in part (c). 3 2. (20 points total) (a) (3 pts) We need to verify that the solution to x = x(1  x) g(x) (13) is given by xs = (  1)/, i.e., g(xs ) = xs . By plugging in xs into (13) for g(xs ) we obtain (  1) (  1) xs (1  xs ) = (  1) (  1) 1 = (  1) = (  1) 1  (  1)(  + 1) = (  1) (  1) = g(xs ) = xs = (14) (b) (2 pts) To verify that g (xs ) = 2  we first differentiate g(x) with respect to x g (x) = (1  2x). Plugging in xs gives us: g (xs ) = (1  2xs ) = 12 =  2 + 2 g (xs ) = 2  . 1 (15) (c) (5 pts) We need to write a Matlab program which implements the fixed point iteration algorithm for = 2.8, starting at x0 = 0.7 and iterating at least 100 times. Running the code below should give you the following output: The fixed point is: 0.6429 which indeed shows that you converge to the expected value of xs = 0.6429. 4 % % % Problem 2( c ) % % % lambda = 2 . 8 ; x = 0.7; for i = 1:1000 x = lambda x(1x ) ; end disp ( ' The f i x e d p o i n t i s : ' ) disp ( x ) % I n i t i a l value % g(x) (d) (5 pts) For = 3.2, the fixed point iteration algorithm is no longer guarantee to converge to xs . Therefore, we must modify the program in part (c) to apply the fixed point iteration algorithm for this value of , again starting with x0 = 0.7
% % % Problem 2( d ) % % % lambda = 3 . 2 ; x = 0.7; for i = 1:1000 x = lambda x(1x ) ; end av ( 1 ) = lambda ; xv ( 1 ) = x ; for i = 1:100 av ( i +1) = lambda ; xv ( i +1) = lambda xv ( i )(1  xv ( i ) ) ; end disp ( ' The v a l u e s o f x n c o n v e r g e t o : ' ) disp ( u n i q u e ( xv ) ) % Returns v a l u e s o f xv w i t h no r e p e t i t i o n % I n i t i a l value % I n t e g r a t e t h e t r a n s i e n t s away % g(x) The above m.file should return: The values of xn converge to: 0.5130 0.7995. Notice that the solutions do not correspond to those computed using the formula xs = (  1)/. For this value of , xs is unstable, meaning that the algorithm with initial value near xs does not converge to xs . Instead, we find that the algorithm converges to a "period2" solution which alternates between two different values of x. We say that a "birfurcation" has occured between = 2.8 and = 3.2. This is a perioddoubling bifurcation because we have gone from a period1 solution, xs , to a period2 solution being stable. This bifurcation occurs at the value x at which g (xs ) = 1. 5 (e) (5 pts) Now, we repeat part (d) but for = 3.5. Modifying the program gives us: The values of xn converge to: 0.3828 0.5009 0.8269 0.8750. In this case, the period2 solution form part (c) underwent a perioddoubling bifurcation, hence we have a period4 solution for this problem. 3. (20 points total) (a) (2 pts) We need to find two h values which bracket the root. 12 10 8 6 f(h) 4 2 0 2 0 0.5 1 h 1.5 2 Figure 2: Problem 3a. From Figure 2, we can pick out 1 and 2 as possible values of h. (b) (3 pts) For this problem, we will find an approximation to the root using the bisection method. Here we use f=inline(`(1/sqrt(2*h))tanh(sqrt(h/2))',`h') which will create an inline function in Matlab then, typing bisect(f,1,2) calls the bisect function and finds the root of f between the point h = 1 and h = 2. The output of bisect.m should give us that the root is 1.1910. 6 (c) (2 pts) The first derivative of f (h) is: d d f (h) = dh dh 1  tanh 2h h 2 h 2 h 2 1 2 2h (16) 1 f (h) =  h3/2  sech2 2 2 =  1 1  sech2 2h 2h 2 2h (d) (3 pts) For this problem, we will find an approximation to the root using the Newton's method. Like in part (b) we define f=inline(`(1/sqrt(2*h))tanh(sqrt(h/2))',`h') and df = inline(`1/(2*h*sqrt(2*h)) 1/(2*sqrt(2*h))*sech(sqrt(h/2))^ 2',`h'). Then, the newtraph(f,df,1) command find the root of f (h), with initial guess 1. The output of newtraph.m should give us that the root is 1.1910. (e) (8 pts) We need to verify that the equation f (h) = 0 can be written as h= So, 1 f (h) = 0 =  tanh 2h 1 2h = h tanh 2 h = 1 2 tanh2
h 2 1 tanh2 ( 2 h/2) g1 (h) (17) h 2 g1 (h) (18) Iterations of hn1 = g1 (hn ) converge to 1.1910. We also need to verify that the equation f (h) = 0 can be written as h = 2[tanh1 (1/ 2h)]2 g2 (h) So, 2h = tanh tanh1 1 2h = h 2
1 (19) 1
h 2 h = 2 tanh 7 1 2h 2 g2 (h) (20) Iterations of hn1 = g2 (hn ) do not converge to 1.1910. (f) (2 pts) The solution of f (h) = 0 using the Matlab command fzero is 1.1910.
% % % Problem 3( a ) % % % % C r e a t e an i n l i n e f u n c t i o n f o r f w i t h i n p u t argument h f = i n l i n e ( ' ( 1 / s q r t ( 2 h))  tanh ( s q r t ( h / 2 ) ) ' , ' h ' ) ; fplot ( f , [ 0 , 2 ] ) % P l o t i n l i n e f u n c t i o n f o r 0 <= h <= 2 grid on ; % Turns on g r i d l i n e s xlabel ( ' h ' ) ; ylabel ( ' f ( h ) ' ) ; % % % Problem 3( b ) % % % f = i n l i n e ( ' ( 1 / s q r t ( 2 h))  tanh ( s q r t ( h / 2 ) ) ' , ' h ' ) ; b = bisect ( f ,1 ,2); % Finds r o o t u s i n g b i s e c t i o n % % % Problem 3( d ) % % % f = i n l i n e ( ' ( 1 / s q r t ( 2 h))  tanh ( s q r t ( h / 2 ) ) ' , ' h ' ) ; d f = i n l i n e ( ' 1/(2h s q r t ( 2 h )) 1/(2 s q r t ( 2 h ) ) s e c h ( s q r t ( h / 2 ) ) ^ 2 ' , ' h ' ) ; d = newtraph ( f , df , 1 ) ; % Finds r o o t u s i n g Newton ' s method w i t h i n i t i a l g u e s s 1 % % % Problem 3( e ) % % % g1 = 1 ; for i = 0:10000 temp = 1 / ( 2 tanh ( sqrt ( g1 / 2 ) ) ^ 2 ) ; error = ( temp  g1 ) / temp ; g1 = temp ; i f abs ( error ) < 0 . 0 0 0 0 0 1 disp ( ' g 1 c o n v e r g e s ! ! ! ' ) ; disp ( g1 ) ; break ; end end g2 = 1 ; for i = 0:10000 temp = 2 ( atanh ( 1 / sqrt ( 2 g2 ) ) ) ^ 2 ; error = ( temp  g2 ) / temp ; g2 = temp ; i f abs ( error ) < 0 . 0 0 0 0 0 1 disp ( ' g 2 c o n v e r g e s ! ! ! ' ) ; disp ( g2 ) ; break ; end end % % % Problem 3( f ) % % % f r o o t = fzero ( f , 1 ) ; 8 ...
View
Full
Document
This homework help was uploaded on 04/07/2008 for the course ME 17 taught by Professor Milstein during the Spring '07 term at UCSB.
 Spring '07
 Milstein

Click to edit the document details