MAE 107 Homework 8 Solutions 1. Newton s method to solve 3exp( x) = 2x starting at x 0 = 11. With chosen f(x), indicate x n, f(x n ), and f (x n ) at each step stopping at the first n such that f(x n ) 1 10 10. Start with f(x) of the form f(x) = 3exp( x) 2x Setting f(x) = 0, Newton s method may be implemented on f(x) to obtain the roots of the function. x 0 = 11 f(x 0 ) = 21.999949894898 f (x 0 ) = 2.000050105102 n = 1 x 1 = x 0 f(x 0) f (x 0 ) = 0.000300623083 f(x 1 ) = 2.998497020134 f (x 1 ) = 4.999098266299 n = 2 x 2 = x 1 f(x 1) f (x 1 ) = 0.600108200451 f(x 2 ) = 0.446040372018 f (x 2 ) = 3.646256772920 n = 3 x 3 = x 2 f(x 2) f (x 2 ) = 0.722436494863 f(x 3 ) = 0.011830200936 f (x 3 ) = 3.456703190661 n = 4 x 4 = x 3 f(x 3) f (x 3 ) = 0.725858889058 f(x 4 ) = 0.000008521300 f (x 4 ) = 3.451726299416 1
n = 5 x 5 = x 4 f(x 4) f (x 4 ) = 0.725861357765 f(x 5 ) = 0.000000000004 < 1 10 10 f (x 5 ) = 3.451722715534 Therefore, x 5 = 0.725861357765 is a close enough approximation to solve the initial equation within a tolerance of 1 10 10. 2. Given the equation E e sin(e) M = 0, for angle E given M [0, 2π) with e as a known parameter. Supposing e (0, 0.25) and initial E 0 = M with understanding that sin(e) 1, what is the worst case error for E 0? Given the form of the equation, the left hand side will represent the error, meaning any value that the left hand side yields which is not zero is an error term. Taking the absolute value, the error can be expressed as e 0 = E 0 e sin(e 0 ) M e 0 = e sin(e 0 ), E 0 = M e 0 e (1) e 0 e < 0.25 e max 0 = 0.25 Where e is a known parameter in (0, 0.25). Errors for Newton s method for solution of f(e) 0 satisfy the relation e k+1 ˆKe 2 k where ˆK = max ζ,η f (ζ) 2f (η) Obtain a tight bound for ˆK for this problem then use that to obtain a bound for the errors in the second step and in the third step of some Newton s method iteration. How many steps would be required to obtain an estiamte with an error no greater than 10 7? Based on that, how many trigonometric function evaluations would be necessary in that Newton s method iteration? 2
f(e) = E e sin(e) M f (E) = 1 e cos(e) f (E) = e sin(e) ˆK = max f (ζ) ζ,η 2f (η) = max ζ f (ζ) 2 max η f (η) = e, e (0, 0.25) 2 1 e ˆK 0.25 2 1 0.25 0.25 2 (0.75) 1 6 So, with a ˆK 1 6, a bound of the error at the first step can be approximated which can be used to bound the error at the second step and so on. Using the maximum error with the initial e 1 ˆK e 2 0 1 6 0.252 e 1 0.0104 e 2 ˆK e 2 1 1 6 0.01042 e 2 = 1.8084 10 5 e 3 ˆK e 2 2 1 6 (1.8084 10 5 ) 2 e 3 5.4508 10 11 < 10 7 So, the third step will yield an approximation which will have an associated error less than 10 7. So, at n = 3, a total of 6 trigonometric evaluations would be required, because for each step f(x n ) and f (x n ) will both be computed with a sin evaluation for f(x n ) and a cos evaluation forf (x n ). Two evaluations at step 0 to obtain an approximation for x 1, two more evaluations at step 1 to obtain an approximation for x 2, and two final evaluations at step 2 to obtain an approximation for x 3 which is known to satisfy the error criterion. A simple MATLAB script given by MAE107 2018 HW 8 P 2.m might be used to assist in this analysis. 1 %% 2 % MAE107 Homework 8 Problem 2 3 % O b j e c t i v e : Determine the number o f s t e p s r e q u i r e d to s a t i s f y some 4 % guaranteed e r r o r f o r Newton s Method 5 % 3
6 % Input V a r i a b l e s : None 7 % 8 % Output V a r i a b l e s : None 9 % 10 % Functions Called : None 11 % 12 %% 13 % Define bounded K hat and e0 terms 14 K hat = 1 / 6 ; 15 e0 = 0. 2 5 ; 16 % Define e p s i l o n value 17 eps = 1E 7; 18 % Print i n i t i a l e r r o r 19 f p r i n t f ( e 0 = %.12 f \n, e0 ) ; 20 % Begin i t e r a t i o n count 21 n = 1 ; 22 % Perform while loop to determine e r r o r bound per s t e p 23 while e0 > eps 24 % Determine new e r r o r 25 en = K hat e0 ˆ 2 ; 26 % Print e r r o r at s t e p 27 f p r i n t f ( e %i = %.12 f \n, [ n en ] ) ; 28 % Update v a l u e s 29 e0 = en ; 30 n = n+1; 31 end 32 % Take away the e x t r a count on n 33 n = n 1; The console output is the following: e 0 = 0.250000000000 e 1 = 0.010416666667 e 2 = 0.000018084491 e 3 = 0.000000000055 3. For this problem, three scripts will be utilized, MAE107 2018 HW 8 P 3.m, secant method.m, and noideatwo.m. 1 f u n c t i o n [ x, y ] = secant method ( x0, x1, f, eps, nmax) 2 % O b j e c t i v e : Perform s e c a n t method i t e r a t i o n f o r some f u n c t i o n 3 % d e f i n e d by the handle f u n t i l some e p s i l o n i s s a t i s f i e d 4 % or some maximum number o f i t e r a t i o n s i s reached. 5 % 6 % Input V a r i a b l e s : x0 and x1 : I n i t i a l v a l u e s f o r r o o t e s t i m a t i o n 7 % f : Function handle f o r e v a l u a t i o n o f p o i n t s 8 % eps : Error c r i t e r i o n value 9 % nmax : Maximum number o f i t e r a t i o n s b e f o r e stop 10 % 11 % Output V a r i a b l e s : x : Output v e c t o r o f approximate r o o t p o i n t s 12 % y : Output v e c t o r o f point e v a l u a t i o n s, f ( x ) 13 % 14 % Functions Called : f : Function f o r which r o o t i s estimated by 15 % s e c a n t method 4
16 % 17 % Default i t e r a t i o n count / e r r o r t o l e r a n c e 18 i f nargin < 5 19 nmax = 1 0 0 ; 20 i f nargin < 4 21 eps = 1e 6; 22 end 23 end 24 25 % P r e a l l o c a t i o n 26 x = z e r o s ( 1, nmax) ; 27 y = z e r o s ( 1, nmax) ; 28 % I n i t i a l i z a t i o n 29 x ( 1 ) = x0 ; 30 x ( 2 ) = x1 ; 31 y ( 1 ) = f ( x0 ) ; 32 y ( 2 ) = f ( x1 ) ; 33 % Secant Method Loop 34 i = 3 ; 35 e r r o r = abs ( y ( 2 ) ) ; 36 while e r r o r > eps && i < nmax % Two c o n d i t i o n a l a r g s f o r eps and nmax 37 % Find c u r r e n t x 38 x ( i ) = x ( i 1) y ( i 1) ( x ( i 1) x ( i 2) ) /( y ( i 1) y ( i 2) ) ; 39 % Evaluate c u r r e n t y 40 y ( i ) = f ( x ( i ) ) ; 41 e r r o r = abs ( y ( i ) ) ; 42 i = i + 1 ; 43 end 44 % Truncate v e c t o r s o f e x t r a z e r o s 45 x = x ( 1 : i 1) ; 46 y = y ( 1 : i 1) ; 47 end 1 f u n c t i o n [ f ] = noideatwo ( x ) 2 % O b j e c t i v e : Function d e s c r i p t i o n f o r problem 3 o f homework 8 3 % 4 % Input V a r i a b l e s : x : Point o f e v a l u a t i o n 5 % 6 % Output V a r i a b l e s : y : Function e v a l u a t i o n 7 % 8 % Functions Called : None 9 c1 = x ; 10 f o r i 1 = 1 : 3 11 c1 = cos ( c1 )+x+3; 12 end 13 f=c1 ; 14 end 1 %% 2 % MAE107 Homework 8 Problem 3 S c r i p t 3 % 4 % O b j e c t i v e : Use s e c a n t method to approximate the r o o t o f some 5 % f u n c t i o n d e f i n e d by noideatwo.m 6 % 7 % Input V a r i a b l e s : None 8 % 9 % Output V a r i a b l e s : None 5
10 % 11 % Functions Called : noideatwo.m: Given f u n c t i o n d e s c r i p t i o n f o r r o o t 12 % approximation 13 % secant method.m: G e n e r a l i z e d Secant Method S c r i p t 14 % 15 %% 16 %%%%%%%%%%%%%%% 17 c l e a r a l l ; 18 c l o s e a l l ; 19 % Define I n i t i a l x v a l u e s 20 x0 = 1 ; 21 x1 = 3 ; 22 % Define noideatwo f u n c t i o n handle 23 f = @noideatwo ; 24 % Define Epsilon 25 eps = 1E 10; 26 % Define some maximum number o f i t e r a t i o n s i n c a s e i t can t s a t i s f y e p s i l o n 27 nmax = 1 0 0 ; 28 [ x, y ] = secant method ( x0, x1, f, eps, nmax) ; 29 e r r o r = abs ( y ( end ) ) ; 30 % Print r e s u l t s 31 f o r i = 1 : l e n g t h ( x ) 32 k=i 1; 33 f p r i n t f ( x %i = %.12 f and, [ k x ( i ) ] ) ; % Print x e s t i m a t e s 34 f p r i n t f ( f ( x %i ) = %.12 f \n, [ k y ( i ) ] ) ; % Print f ( x ) e v a l u a t i o n s 35 end The console output is the following: x 0 = 1.000000000000 and f(x 0) = 3.226954896959 x 1 = 3.000000000000 and f(x 1) = 6.999949409171 x 2 = -0.710553718811 and f(x 2) = 2.562842137030 x 3 = -2.853743603352 and f(x 3) = 0.818271971383 x 4 = -3.858983889129 and f(x 4) = -0.237908847635 x 5 = -3.632549595229 and f(x 5) = 0.205981439315 x 6 = -3.737623445996 and f(x 6) = 0.006201768577 x 7 = -3.740885257889 and f(x 7) = -0.000201644322 x 8 = -3.740782543000 and f(x 8) = 0.000000158645 x 9 = -3.740782623748 and f(x 9) = 0.000000000004 4. Consider attempting to solve tan(3x) = 2x + 1 2 via the fixed point method. A form under which the method is guaranteed to converge would be x = 1 3 atan(2x + 1 2 ). This can be proven by taking the first derivative and bounding its absolute value under 1. 6
x = g(x) g(x) = 1 3 atan(2x + 1 2 ) g 8 (x) = 48x 2 + 24x + 15 g (x) < 1, x R The form of g(x) is continuously differentiable, so a γ to define the convergence rate could be directly computed. max x R g (x) = γ < 1 x = 1 ( 4, g 1 ) = 2 4 3 γ = 2 3 This result shows that the fixed point α is unique, the iteration x n+1 = g(x n ) converges to α for any guess x 0 R, and the error estimate becomes α x n γn 1 γ x 1 x 0 ( ) 2 n α x n 3 x 1 x 0 3 Finally, the following limit also holds α x n+1 lim n inf α x n = g (α) Then, there is one other form to consider, so let x = 1 2 tan(3x) 1 4 which will not guarantee convergence. be the alternative form x = h(x) h(x) = 1 2 tan(3x) 1 4 g (x) = 3 2 sec2 (3x) g (x) > 1, x R 7
So, for any interval [a, b] which exists such that h(x) [a, b], there is no constant γ which would guarantee h (x) γ < 1. Therefore, h(x) does not satisfy the fixed-point theorem for the convergence of sequence x n+1 = h(x n ) to some unique fixed point α [a, b]. 5. For this problem, two scripts will be used, MAE107 2018 HW 8 P 5.m and fp method.m. For analysis, a maximum of 100 iterations will be allowed for either form, and a satisfactory epsilon will be given by ɛ = 1 10 7. 1 f u n c t i o n [ x, n ] = fp method ( x0, f, nmax, eps ) 2 % O b j e c t i v e : Use f i x e d point method to obtain a convergence point 3 % based on the i t e r a t i o n x n = f ( x n 1) 4 % 5 % Input V a r i a b l e s : x0 : I n i t i a l point o f i t e r a t i o n 6 % f : Function handle f o r f i x e d point i t e r a t i o n 7 % nmax : Maximum number o f i t e r a t i o n s 8 % eps : Error c r i t e r i o n 9 % 10 % Output V a r i a b l e s : x : Fixed point convergence value 11 % n : I t e r a t i o n s t e p f o r convergence 12 % 13 % Functions Called : f : Right hand s i d e f u n c t i o n f o r f i x e d point 14 % i t e r a t i o n 15 %% 16 % Set d e f a u l t v a l u e s i f input arguments not f u l l 17 i f nargin < 4 18 eps = 1e 10; 19 i f nargin < 3 20 nmax = 1 0 0 ; 21 end 22 end 23 % I n i t i a l i z e v a l u e s f o r loop 24 n = 1 ; 25 x = f ( x0 ) ; 26 e = abs ( x x0 ) ; 27 % Begin loop with e x i t c o n d i t i o n s given by eps and nmax 28 while max( e ) > eps && n < nmax 29 % Obtain new point 30 x = f ( x0 ) ; 31 % Determine new e r r o r 32 e = abs ( x x0 ) ; 33 % Update v a l u e s f o r next s t e p 34 x0 = x ; 35 n = n+1; 36 end 1 %% 2 % MAE 107 Homework 8 Problem 5 3 % 4 % O b j e c t i v e : Use Fixed Point method to f i n d convergene point with 5 % two d i f f e r e n t forms o f equation 6 % 7 % Input V a r i a b l e s : None 8 % 9 % Output V a r i a b l e s : None 10 % 11 % Functions C a l l e d : None ( See Anonymous Functions Defined i n Code ) 8
12 % 13 %% 14 % Define i n i t i a l guess v e c t o r 15 x0 = [ 0 ; 2; 1 0 0 0 ] ; 16 % Convenient to d e f i n e two anonymous f u n c t i o n s f o r e a s i e r argument p a s s i n g 17 g = @( x ) (1/3) atan (2 x+(1/2) ) ; % Form 1 : Expect convergence 18 h = @( x ) (1/2) tan (3 x ) (1/4) ; % Form 2 : Do not expect convergence 19 % Define two p o t e n t i a l t h r e s h o l d s f o r h a l t i n g f i x e d point i t e r a t i o n 20 eps = 1e 7; % Absolute e r r o r between two i t e r a t i o n s 21 nmax = 1 0 0 ; % Maximum Number o f I t e r a t i o n s 22 % P r e a l l o c a t e v e c t o r s f o r l o o p i n g over x0 v e c t o r 23 x gvec = z e r o s ( l e n g t h ( x0 ), 1 ) ; % Point o f convergence f o r form g 24 x hvec = z e r o s ( l e n g t h ( x0 ), 1 ) ; % Point o f convergence f o r form h 25 n g = z e r o s ( l e n g t h ( x0 ), 1 ) ; % Number o f i t e r a t i o n s f o r form g 26 n h = z e r o s ( l e n g t h ( x0 ), 1 ) ; % Number o f i t e r a t i o n s f o r form h 27 f o r i = 1 : l e n g t h ( x0 ) 28 % Fixed Point I t e r a t i o n f o r form g 29 [ x gvec ( i ), n g ( i ) ] = fp method ( x0 ( i ), g, nmax, eps ) ; 30 % Print R e s u l t s 31 f p r i n t f ( %i i t e r a t i o n s f o r g to attempt, n g ( i ) ) ; 32 f p r i n t f ( convergence to %.8 f, x gvec ( i ) ) ; 33 f p r i n t f ( using i n i t i a l guess %.0 f \n, x0 ( i ) ) ; 34 % Fixed Point I t e r a t i o n f o r form h 35 [ x hvec ( i ), n h ( i ) ] = fp method ( x0 ( i ), h, nmax, eps ) ; 36 % Print R e s u l t s 37 f p r i n t f ( %i i t e r a t i o n s f o r h to attempt, n h ( i ) ) ; 38 f p r i n t f ( convergence to %.8 f, x hvec ( i ) ) ; 39 f p r i n t f ( using i n i t i a l guess %.0 f \n, x0 ( i ) ) ; 40 end The console output is the following: 16 iterations for g to attempt convergence to 0.26754692 using initial guess 0 100 iterations for h to attempt convergence to -0.90734305 using initial guess 0 18 iterations for g to attempt convergence to 0.26754690 using initial guess -2 100 iterations for h to attempt convergence to -4.63273138 using initial guess -2 16 iterations for g to attempt convergence to 0.26754696 using initial guess 1000 100 iterations for h to attempt convergence to -4.24220727 using initial guess 1000 f(x) x 0 n α ɛ n max g(x) 0 16 0.26754692 1 10 7 100 g(x) -2 18 0.26754690 1 10 7 100 g(x) 1000 16 0.26754696 1 10 7 100 h(x) 0 100-0.90734305 1 10 7 100 h(x) -2 100-4.63273138 1 10 7 100 h(x) 1000 100-4.24220727 1 10 7 100 So, it would appear that g(x) converged reasonably well for all initial guesses, however h(x) required the maximum number of iterations and showed no consistency in converging to some fixed point α. 9
6. For this problem, two scripts will be used, MAE107 2018 HW 8 P 6.m and fp method.m. First, x 7 is determined using a two equation, two unknown fixed point iteration. Then, ˆKk is determined for each step in k [1, 2,...6] and is used to estimate what x 15 x 14 will be. This estimate is then compared to the actual value of x 15 x 14. 1 f u n c t i o n [ x, n ] = fp method ( x0, f, nmax, eps ) 2 % O b j e c t i v e : Use f i x e d point method to obtain a convergence point 3 % based on the i t e r a t i o n x n = f ( x n 1) 4 % 5 % Input V a r i a b l e s : x0 : I n i t i a l point o f i t e r a t i o n 6 % f : Function handle f o r f i x e d point i t e r a t i o n 7 % nmax : Maximum number o f i t e r a t i o n s 8 % eps : Error c r i t e r i o n 9 % 10 % Output V a r i a b l e s : x : Fixed point convergence value 11 % n : I t e r a t i o n s t e p f o r convergence 12 % 13 % Functions Called : f : Right hand s i d e f u n c t i o n f o r f i x e d point 14 % i t e r a t i o n 15 %% 16 % Set d e f a u l t v a l u e s i f input arguments not f u l l 17 i f nargin < 4 18 eps = 1e 10; 19 i f nargin < 3 20 nmax = 1 0 0 ; 21 end 22 end 23 % I n i t i a l i z e v a l u e s f o r loop 24 n = 1 ; 25 x = f ( x0 ) ; 26 e = abs ( x x0 ) ; 27 % Begin loop with e x i t c o n d i t i o n s given by eps and nmax 28 while max( e ) > eps && n < nmax 29 % Obtain new point 30 x = f ( x0 ) ; 31 % Determine new e r r o r 32 e = abs ( x x0 ) ; 33 % Update v a l u e s f o r next s t e p 34 x0 = x ; 35 n = n+1; 36 end 1 %% 2 % MAE 107 Homework 8 Problem 6 3 % 4 % O b j e c t i v e : Determine s o l u t i o n to a s e t o f e q u a t i o n s using f i x e d 5 % point method then use the e s t i m a t e o f K hat to e s t i m a t e 6 % the Euclidean norm o f the d i f f e r e n c e in the v e c t o r s 7 % between the 14 th and the 15 th i t e r a t i o n s 8 % 9 % Input V a r i a b l e s : None 10 % 11 % Ouput V a r i a b l e s : None 12 % 13 % Functions Called : fpmethod.m: G e n e r a l i z e d Fixed Point method to allow f o r 14 % n e q u a t i o n s and n uknowns 10
15 % 16 % ( See l o c a l f u n c t i o n s d e f i n e d below main loop 17 % 18 %% 19 c l e a r a l l ; 20 c l o s e a l l ; 21 % Define I n i t i a l Conditions 22 x0 = [ 0 ; 0 ] ; 23 % Define Function Handle 24 h = @f p6 ; 25 % Define Epsilon Error C r i t e r i o n 26 eps = 1e 10; 27 % Define Step Number f o r determining K hat v e c t o r 28 n = 7 ; 29 % P r e a l l o c a t e v e c t o r s / i n i t i a l i z e 30 xk = z e r o s ( l e n g t h ( x0 ), n+1) ; 31 xk ( :, 1 ) = x0 ; 32 K t i l d e k = z e r o s (n 1,1) ; 33 num = z e r o s ( 2, n 1) ; 34 euc num = z e r o s (n 1,1) ; 35 den= z e r o s ( 2, n 1) ; 36 euc den = z e r o s (n 1,1) ; 37 % Begin Loop f o r b u i l d i n g v e c t o r o f xk going to s t e p 15 38 f o r i = 1 : 1 5 39 xk ( :, i +1) = fp method ( xk ( :, i ), h, 1, eps ) ; 40 end 41 % Print e s t i m a t e f o r x 7 42 f p r i n t f ( x 7 = \n%.12 f \n%.12 f \n\n, xk ( :, 8 ) ) ; 43 % Begin Loop f o r Determining K hat using the f i r s t 7 i t e r a t i o n s 44 f o r k = 2 : n 45 num ( :, k 1) = xk ( :, k+1) xk ( :, k ) ; % Numerator term 46 euc num ( k 1) = euc norm (num ( :, k 1) ) ; %Euclidean norm o f numerator 47 den ( :, k 1) = xk ( :, k ) xk ( :, k 1) ; % Denominator term 48 euc den ( k 1) = euc norm ( den ( :, k 1) ) ; % Euclidean norm o f denominator 49 K t i l d e k ( k 1) = euc num ( k 1)/ euc den ( k 1) ; % K hat k e v a l u a t i o n 50 f p r i n t f ( K t i l d e %i = %.12 f \n, [ k 1 K t i l d e k ( k 1) ] ) ; % Print r e s u l t s 51 end 52 % Estimate the Euclidean norm d i f f e r e n c e at s t e p 15 53 % Since f u n c t i o n i s assumed L i p s c h i t z continuous, i t i s assumed t h e r e 54 % e x i s t s some cosntant L < 1 such that x n+1 x n <= L x n x n 1. 55 % From K hat k, a l o w e r bound approximation f o r L can be taken by the 56 % maximum value o f K hat k 57 % 58 L = max( K t i l d e k ) ; 59 L = K t i l d e k ( 5 ) ; 60 % Print what our L i p s c h i t z constant approximation w i l l be 61 f p r i n t f ( \ nwill use L = %.12 f to e s t i m a t e x 15 x 14 \ n,l) ; 62 % 63 % Now compute x 15 x 14 = Lˆ8 x 7 x 6 64 e u c n o r m 1 5 e s t = Lˆ(15 n ) euc num (n 1) ; 65 % Obtain the a c t u a l Euclidean norm d i f f e r e n c e at s t e p 15 66 euc norm 15 = euc norm ( xk ( :, 1 6 ) xk ( :, 1 5 ) ) ; 67 % Print r e s u l t s 68 f p r i n t f ( The estimated value o f x 15 x 14 = %.16 f \n, e u c n o r m 1 5 e s t ) ; 69 f p r i n t f ( The a c t u a l value o f x 15 x 14 = %.16 f \n, euc norm 15 ) ; 70 %% 11
71 % n v a r i a b l e n equation f u n c t i o n 72 f u n c t i o n [ f ] = f p 6 ( x ) 73 % O b j e c t i v e : Set o f e q u a t i o n s d e f i n e d in problem 6 d e s c r i p t i o n f o r 74 % f i x e d point i t e r a t i o n 75 % 76 % Input V a r i a b l e s : x : Vector o f v a l u e s f o r e v a l u a t i o n 77 % 78 % Output V a r i a b l e s : f : Vector o f f u n c t i o n e v a l u a t i o n s 79 % 80 % Functions Called : None 81 % 82 f = z e r o s ( l e n g t h ( x ), 1 ) ; 83 i f l e n g t h ( f ) = 2 84 e r r o r ( Function e x p e c t s an input v e c t o r o f l e n g t h 2, but i t ) ; 85 e r r o r ( r e c e i v e d a v e c t o r o f some other l e n g t h ) ; 86 end 87 f ( 1 ) = 0. 5 atan ( x ( 1 )+x ( 2 ) ) + 7 ; 88 f ( 2 ) = s i n ( x ( 1 ) x ( 2 ) ) /(2 exp(1+x ( 2 ) ˆ2) ) ; 89 end 90 91 % Euclidean Norm Function 92 f u n c t i o n [ norm ] = euc norm ( x ) 93 % O b j e c t i v e : Obtain the Euclidean norm o f an input v e c t o r 94 % 95 % Input V a r i a b l e s : x : Input v e c t o r 96 % 97 % Output V a r i a b l e s : norm : Euclidean norm value o f input v e c t o r 98 % 99 % Functions Called : None 100 % 101 % Define a sum o f square v a l u e s 102 sq sum = 0 ; 103 % Begin loop to sum the square v a l u e s 104 f o r i = 1 : l e n g t h ( x ) 105 sq sum = sq sum + x ( i ) ˆ 2 ; 106 end 107 % Take the square r o o t o f the sum 108 norm = s q r t ( sq sum ) ; 109 end The console output is the following: x 7 = 7.722386213080 0.170571452848 K tilde 1 = 0.103513976346 K tilde 2 = 0.075668473046 K tilde 3 = 0.094047320638 K tilde 4 = 0.117114172018 K tilde 5 = 0.114505016479 K tilde 6 = 0.114812878200 Will use L = 0.117114172018 to estimate x 15-x 14 12
The estimated value of x 15-x 14 = 0.0000000000002810 The actual value of x 15-x 14 = 0.0000000000002392 There are, of course, multiple ways to utilize K k to obtain an estimate x 15 x 14. For example, one could use the final value obtained from the K k values. Using K 6 will yield an estimate that is around 0.0000000000002397. This ends up being a bit closer to the actual result than using the maximum K k value, because using the maximum will provide a more conservative estimate. Using K 5 will yield a result that is around 0.0000000000002346 which is now slightly below the actual result. Any estimate between 0.0000000000002346 and 0.0000000000002810 would be a reasonable approximation in this case. 7. Lagrange interpolation for second-order polynomial through (x 0, y 0 ) = (1, 4), (x 1, y 1 ) = (3, 2), and (x 2, y 2 ) = (7, 8). Reduce solution to form y = c 0 + c 1 x + c 2 x 2. P (x) = 2 Pj 2 (x) j=0 Pj 2 (x) = y j L 2 j(x) 2 L 2 x x k j(x) = x j x k k=0,k j P (x) = P 2 0 (x) + P 2 1 (x) + P 2 2 (x) P (x) = y 0 L 2 0(x) + y 1 L 2 1(x) + y 2 L 2 2(x) [( ) ( )] [( ) ( x x1 x x2 x x0 x x2 P (x) = y 0 + y 1 x 0 x 1 x 0 x 2 x 1 x 0 x 1 x 2 [( ) ( )] [( ) ( )] x 3 x 7 x 1 x 7 P (x) = 4 + 2 8 1 3 1 7 3 1 3 7 ( 1 P (x) = 4 12 x2 5 6 x + 21 ) ( + 2 1 12 8 x2 + x 7 ) 8 8 P (x) = 1 3 x2 10 3 x + 7 1 4 x2 + 2x 7 4 1 3 x2 + 4 3 x 1 P (x) = 1 4 x2 + 17 4 )] [( x x0 + y 2 x 2 x 0 ) ( )] x 3 [( x 1 7 1 ( 1 24 x2 1 6 x + 1 8 7 3 ) ) ( )] x x1 x 2 x 1 Where c 0 = 17 4, c 1 = 0, and c 2 = 1 4. 13