Winter 2016 1. Solutions for Root Finding Practice Problems CS371/AM242 [16 marks] a) [2 marks] π(π₯) = (π₯ + βπ₯) β (20 β π₯ + β20 β π₯) β 155.55 b) [8 marks] Note, with f(x) as above, we have that 1 1 π β² (π₯) = (1 + ) (20 β π₯ + β20 β π₯) β (π₯ + βπ₯) (1 + ) 2βπ₯ 2β20 β π₯ % fn.m function [ val ] = fn( x ) % Calculates (x+sqrt(x))*(20-x + sqrt(20-x)) - 155.55 y = 20-x; val = (x+sqrt(x)) * (y + sqrt(y)) - 155.55; end % fnprime.m function [ val ] = fnprime( x ) % Calculates the derivative of fn(x) y = 20-x; val1 = (1+1/(2*sqrt(x)))* (y + sqrt(y)); val2 = (x+sqrt(x))*(1 + 1/(2*sqrt(y))); val = val1 - val2; end % a5q1b_soln.m % choose initial guesses (x0=1, x0=9. x0=another value (5 here) initial = [1,9,5]; % for each initial value, perform steps of Newton's method until the % value of fn at x is <= 1.0e-6 for i = 1:3 x = initial(i); fx = fn(x); while (abs(fx) > 1.0e-6) % display the value of x (and its function value) info = ['x= ' num2str(x) ' f(x)= ' num2str(fx)]; disp(info) % calculate the next iterate fx = fn(x); fprime = fnprime(x); x = x - fx/fprime; end % display the final iterate info = ['x= ' num2str(x) ' f(x)= ' num2str(fx)]; disp(info) disp(blanks(1)) end 1 Winter 2016 Solutions for Root Finding Practice Problems CS371/AM242 My results: >> a1q5b_soln x= 1 f(x)= -108.8322 x= 4.3172 f(x)= -108.8322 x= 6.0608 f(x)= -29.9344 x= 6.486 f(x)= -4.9311 x= 6.5127 f(x)= -0.27575 x= 6.5128 f(x)= -0.0010825 x= 6.5128 f(x)= -1.694e-08 x= x= x= x= x= x= x= x= 9 f(x)= 16.2495 3.3844 f(x)= 16.2495 5.7048 f(x)= -47.4534 6.4338 f(x)= -9.2546 6.5119 f(x)= -0.81793 6.5128 f(x)= -0.0092484 6.5128 f(x)= -1.2358e-06 6.5128 f(x)= -5.6843e-14 x= x= x= x= x= x= 5 f(x)= -18.9838 6.2721 f(x)= -18.9838 6.5048 f(x)= -2.5485 6.5128 f(x)= -0.082198 6.5128 f(x)= -9.7225e-05 6.5128 f(x)= -1.3665e-10 c) [5 marks] Bisection method β note that f(x) is continuous over the i. [1 mark] f(x) is continuous over the interval [1,9], and f(1) = -108.83 < 0 and f(9) = 16.2495 > 0. By the Intermediate Value Theorem, there exists a root of f(x) in the interval [1,9]. ii. [4 marks] Each iteration of the bisection method halves the length of the interval, so after k iterations 1 1 π 1 π 1 πβ3 |ππ β ππ | = |ππβ1 β ππβ1 | = β― = ( ) |π0 β π0 | = ( ) 8 = ( ) 2 2 2 2 So, we are looking for k such that 1 πβ3 ( ) β€ 10β6 β 2πβ3 β₯ 106 β log 2 2πβ3 β₯ log 2 106 β π β 3 β₯ 19.93 β¦ 2 That is, we need k β₯22.93β¦ or about 23 iterations. 2 Winter 2016 Solutions for Root Finding Practice Problems CS371/AM242 2. [16 marks] Fixed point techniques with f(x) = x4 + 2x2 β x - 3 a) [2 marks] x is a fixed point of g(x) if and only if (π₯ + 3 β π₯ 4 ) (π₯ + 3 β π₯ 4 ) π₯= β β π₯2 = β 2π₯ 2 = π₯ + 3 β π₯ 4 β π₯ 4 + 2π₯ 2 β π₯ β 3 = 0 2 2 i.e. if and only if x is a root of f(x). b) [6 marks] My Matlab code to produce the first 20 iterations of the fixed point method with g: % g.m function [ y ] = g( x ) %Produces sqrt((x+3-x^4)/2) y = sqrt( (x+3-x^4) / 2 ); end % a1q6b_soln.m x = 1; for i = 1:20 disp(num2str(x)) x = g(x); end disp(num2str(x)) My results for those 20 iterations: >> a1q6b_soln 1 1.2247 0.99367 Note that the iterates are oscillating back and forth between a value 1.2286 around between 1.22 and 1.25 and a second value between 0.99 and .95. 0.98751 1.2322 Convergence does not appear to be happening (as is possible with fixed 0.98159 point functions if the derivative of g is not well-behaved in the region of a 1.2356 0.97596 root. In this case, g' is undefined when x+3-x4 = 0. 1.2387 0.97068 1.2415 0.96579 1.2441 0.9613 1.2465 0.95723 1.2485 0.95357 1.2504 0.95032 3 Winter 2016 c) Solutions for Root Finding Practice Problems CS371/AM242 [2 marks] x is a fixed point of h(x) if and only if: 3π₯ 4 + 2π₯ 2 + 3 = π₯ β 3π₯ 4 + 2π₯ 2 + 3 = 4π₯ 4 + 4π₯ 2 β π₯ β π₯ 4 + 2π₯ 2 β π₯ β 3 = 0 4π₯ 3 + 4π₯ β 1 i.e. if and only if f(x) = 0. d) [6 marks] Matlab code is virtually identical to that in part b, with just h replacing g. % h.m function [ y ] = h( x ) %Produces (3x^4+2x^2+3)/(4x^3+4x-1) numer = 3*x^4 + 2*x^2 + 3; denom = 4*x^3 + 4*x - 1; y = numer/denom; end % a1q6b_soln.m x = 1; for i = 1:20 disp(num2str(x)) x = h(x); end disp(num2str(x)) Which leads to the following results: >> a1q6d_soln 1 1.1429 This fixed point algorithm converges *very* quickly to a fixed point of h, i.e. a root of f. 1.1245 1.1241 A little background: In the area of the root of f nearby x0=1 (as identified here, around 1.1241 1.1241), g'(x) < -2 (i.e. absolute value > 1) but abs(h(x)) < 1. So, these results support 1.1241 the convergence theory we developed for the fixed point algorithms. 1.1241 1.1241 1.1241 1.1241 1.1241 1.1241 1.1241 1.1241 1.1241 1.1241 1.1241 1.1241 1.1241 1.1241 4 Winter 2016 Solutions for Root Finding Practice Problems 1 1 2 π₯π 3. [10 marks] The iteration π₯π+1 = π₯π + 1 1 CS371/AM242 , is used to find a fixed point of the function π(π₯) = 2 π₯ + π₯ on the interval [β2, β). a) [5 marks] The function x is continuous for over (0, β) - the only discontinuity is when x=0, which is not the range we are considering. If x >0 then g(x) >0, so the value of g 1 1 is in the same range. We see that β2 is a fixed point of g since π(β2) = 2 β2 + = β2 β2 2 + β2 2 = β2. 1 1 The derivative of g(x) is πβ²(π₯) = 2 β π₯ 2 . For any real nonzero x, g'(x)< ½ . Also, for 1 1 xβ₯β2, π₯ 2 β€ 2 so g'(x) β₯ 0. In particular, we see that |g'(x)|<1 on the interval [β2, β). So, by the convergence theorem for fixed point algorithms, the given iteration will converge to x* = β2. b) [5 marks] From (a), we know that limπ π₯π = β2. Now, we just want to know the rate of convergence of the iteration. Fixed point algorithms are known to converge at least linearly (when the converge), so it is at least linear. However, we can show that the convergence in this case is quadratic. Consider the ratio of errors of consecutive iterates: ππ+1 ππ2 π₯π2 + 2 β 2β2π₯ 1 1 π₯ + β β2 π π₯π+1 β π₯ π₯π+1 β β2 1 2 π₯π 2π₯π = = = 2 = 2 = 2 β 2 (π₯π β π₯ ) π₯π β 2β2π₯ + 2 π₯π β 2β2π₯ + 2 2π₯π (π₯π β β2) β So, |ππ+1 | 1 1 = lim = 2 πββ |ππ | πββ 2π₯π 2β2 lim 1 Therefore, convergence is quadratic (q=2) and the asymptotic error constant Ξ»=2 2. β 5
© Copyright 2025 Paperzz