Docsity

Problem Set 4 with Solution Manual | Numerical Computing | MATH 4800, Assignments of Mathematics

Toggle sidebar
bg1
D. Schwendeman
Numerical Computing Problem Set 4
Due:
Monday, 10/17/11
1. Consider the cubic polynomial p(x) = x3−2x2−5x+ 8.
(a) Show that p(x) has a unique root for each of the intervals: [−3,−2], [1,2] and [2,3].
(b) Write a Matlab function or script to determine the three roots of p(x) using the method
of false position (as discussed in class). For each root, use the stopping criterion |xn+1−xn|<
10−6, where xnand xn+1 are successive approximations of the root during the iteration.
2. Consider the functions
f1(x) = x3−2x−5, f2(x) = e−x−x, f3(x) = xsin(x)−1
(a) Newton’s iteration has the form of the fixed-point iteration xn+1 =g(xn), where g(x) =
x−f(x)/f0(x). Determine g(x) for each of the functions, fi(x), i= 1,2,3.
(b) Write a Matlab function or script to determine the smallest positive root of the functions
fi(x), i= 1,2,3, using Newton’s method. You will need to determine a suitable starting
guess, x0, for each case, and use the stopping criterion |xn+1 −xn|<10−12.
3. Consider the fixed-point iteration xn+1 =g(xn), where g(x) = x+ ln(2 −x).
(a) Show that g(x)∈[1/2,3/2] whenever x∈[1/2,3/2]. Show also that |g0(x)|<1 whenever
x∈[1/2,3/2] and so g(x) has a unique fixed point on this interval. (Hint: you must find
the minimum and maximum values of gand g0for x∈[1/2,3/2] to solve this problem.
Also, note that it is not enough to simply check the values of gand g0at the endpoints of
the interval.)
(b) Verify that x= 1 is a fixed point of g(x) and determine the rate of convergence of
the fixed-point iteration (assuming that a starting value x0is chosen on [1/2,3/2]). (Hint:
consider the values of the derivatives of g(x) at x= 1.)
4. Text exercise 5.9, page 249.
5. Write a Matlab function or script to solve the system of nonlinear equations
16x4
1+ 16x4
2+x4
3= 16
x2
1+x2
2+x2
3= 3
x3
1−x2= 0
using Newton’s method. Use x1=x2=x3= 1 as a starting value for the iteration and use
the stopping criterion
q(x1,n+1 −x1,n)2+ (x2,n+1 −x2,n)2+ (x3,n+1 −x3,n )2<10−12
You may use Matlab’s magic backslash to solve any linear systems of equations that arise
in the iteration.
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Problem Set 4 with Solution Manual | Numerical Computing | MATH 4800 and more Assignments Mathematics in PDF only on Docsity!

D. Schwendeman

Numerical Computing Problem Set 4

Due: Monday, 10/17/

  1. Consider the cubic polynomial p(x) = x^3 − 2 x^2 − 5 x + 8. (a) Show that p(x) has a unique root for each of the intervals: [− 3 , −2], [1, 2] and [2, 3]. (b) Write a Matlab function or script to determine the three roots of p(x) using the method of false position (as discussed in class). For each root, use the stopping criterion |xn+1−xn| < 10 −^6 , where xn and xn+1 are successive approximations of the root during the iteration.
  2. Consider the functions

f 1 (x) = x^3 − 2 x − 5 , f 2 (x) = e−x^ − x, f 3 (x) = x sin(x) − 1

(a) Newton’s iteration has the form of the fixed-point iteration xn+1 = g(xn), where g(x) = x − f (x)/f ′(x). Determine g(x) for each of the functions, fi(x), i = 1, 2 , 3. (b) Write a Matlab function or script to determine the smallest positive root of the functions fi(x), i = 1, 2 , 3, using Newton’s method. You will need to determine a suitable starting guess, x 0 , for each case, and use the stopping criterion |xn+1 − xn| < 10 −^12.

  1. Consider the fixed-point iteration xn+1 = g(xn), where g(x) = x + ln(2 − x). (a) Show that g(x) ∈ [1/ 2 , 3 /2] whenever x ∈ [1/ 2 , 3 /2]. Show also that |g′(x)| < 1 whenever x ∈ [1/ 2 , 3 /2] and so g(x) has a unique fixed point on this interval. (Hint: you must find the minimum and maximum values of g and g′^ for x ∈ [1/ 2 , 3 /2] to solve this problem. Also, note that it is not enough to simply check the values of g and g′^ at the endpoints of the interval.) (b) Verify that x = 1 is a fixed point of g(x) and determine the rate of convergence of the fixed-point iteration (assuming that a starting value x 0 is chosen on [1/ 2 , 3 /2]). (Hint: consider the values of the derivatives of g(x) at x = 1.)
  2. Text exercise 5.9, page 249.
  3. Write a Matlab function or script to solve the system of nonlinear equations

16 x^41 + 16x^42 + x^43 = 16 x^21 + x^22 + x^23 = 3 x^31 − x 2 = 0 using Newton’s method. Use x 1 = x 2 = x 3 = 1 as a starting value for the iteration and use the stopping criterion √ (x 1 ,n+1 − x 1 ,n)^2 + (x 2 ,n+1 − x 2 ,n)^2 + (x 3 ,n+1 − x 3 ,n)^2 < 10 −^12

You may use Matlab’s magic backslash to solve any linear systems of equations that arise in the iteration.

Problem 1

Part (a) p(x) is a polynomial, hence continuous everywhere. So if we can show that p changes sign on some interval, then p must have a root on that interval. But p(a)p(b) < 0 for each interval [a, b]. Hence p(a) and p(b) have different signs, so p must have a root between a and b (by the intermediate value theorem). Since there are 3 such intervals, and since p has at most 3 distinct roots (it’s a cubic polynomial), it must be the case that there is a unique root in each interval. This can also be easily verified with a plot of p(x).

Part (b) This method was discussed in class and is similar to the bisection method. Instead of using the midpoint of the interval to update the interval endpoints, however, use the zero of the line connecting the points (a, p(a)) and (b, p(b)). You should find roots x 1 ≈ − 2 .12489, x 2 ≈ 1 .36333, and x 3 ≈ 2 .76156. falsePositionExample.m is below. This code sets up the problem for the first polynomial: it establishes the intervals and feeds myFalsePosition.m the interval, tolerance, and maximum iterations allowed.

1 % Find the roots of the cubic polynomial 2 % 3 % p(x)=xˆ3-2xˆ2-5x+ 4 % 5 % using the method of false position. Give a bracket for 6 % each root and use abs(x(n+1)-x(n))<1e-6 as a stopping 7 % criterion. 8 9 a1=-3; b1=-2; 10 x1=myFalsePosition('falsePositionPolynomial',a1,b1,1e-6,100) 11 12 a2=1; b2=2; 13 x2=myFalsePosition('falsePositionPolynomial',a2,b2,1e-6,100) 14 15 a3=2; b3=3; 16 x3=myFalsePosition('falsePositionPolynomial',a3,b3,1e-6,100)

26 if fx*fa< 0 27 b=x1; fb=fx; 28 else 29 a=x1; fa=fx; 30 end 31 if n> 1 32 if abs(x1-x)<tol 33 x=x1; 34 return 35 end 36 end 37 x=x1; 38 end

Problem 2

Part (a) This is straightforward calculation.

gi(x) = x − f f i′(x) i (x)^

g 1 (x) = x − x^33 −x (^22) −x− 25 g 2 (x) = x − (^) −e−e−xx−−x 1 g 3 (x) = x − (^) x cos(x^ sin(x)+sin(x)−^1 x)

Part (b) To determine your suitable starting guesses, it’s a good idea to plot each function: estimate by eye the location of smallest positive root, and use this (or something close to it) as your starting guess. You should find roots x 1 ≈ 2 .09455148154, x 2 ≈ 0 .56714329041, and x 3 ≈ 1 .11415714087. Similar to the last problem, myNewtonPS4.m sets up the problem by feeding the main program the starting guess, tolerance, function in question, and maximum number of iterations allowed. The code follows.

1 % Use Newton's method to find the smallest positive root 2 % of the functions 3 %

4 % f1=xˆ3-2x-5, f2=exp(-x)-x, f3=xsin(x)- 5 % 6 % with tolerance 1e- 7 8 x1=myNewtonMethod('newtonFunction1',2.0,1e-12,10); 9 x2=myNewtonMethod('newtonFunction2',0.5,1e-12,10); 10 x3=myNewtonMethod('newtonFunction3',1.0,1e-12,10); 11 12 % here are the roots 13 disp(sprintf('Roots = %0.15e %0.15e %0.15e',x1,x2,x3))

The Matlab code defining the functions are newtonFunction1.m,

1 function y=newtonFunction1(x,deriv) 2 3 if deriv== 4 y=xˆ3-2x-5; 5 else 6 y=3xˆ2-2; 7 end newtonFunction2.m,

1 function y=newtonFunction2(x,deriv) 2 3 if deriv== 4 y=exp(-x)-x; 5 else 6 y=-exp(-x)-1; 7 end and newtonFunction3.m.

1 function y=newtonFunction3(x,deriv) 2

1 / 2 ≤ x < 1, zero for x = 1, and negative for 1 < x ≤ 3 /2. Hence g is increasing for 1/ 2 ≤ x < 1 and decreasing for 1 < x ≤ 3 /2. Also, 1/ 2 < g(3/2) < g(1/2) < g(1) < 3 /2; so the values of g are bounded below by g(1/2) and above by g(1) for x ∈ [1/ 2 , 1], and the values of g are bounded below by g(3/2) and above by g(1) for x ∈ [1, 3 /2]. Hence g(x) remains in the desired interval for x ∈ [1/ 2 , 3 /2]. It’s also easy to see that | 1 − x| ≤ | 2 − x|, or |g′(x)| ≤ 1 for x ∈ [1/ 2 , 3 /2], and |g′(x)| < 1 for x in the open interval (1/ 2 , 3 /2).

Part (b) Verifying that g(1) = 1 is a matter of simple computation (and can be checked with WolframAlpha, Matlab, etc.). From our formula above, g′(1) = 0; also, g′′(1) = − 1 6 = 0. Hence the convergence is quadratic (see the discussion on pages 228 and 229 of the textbook).

Problem 4: Exercise 5.9, page 249

To express the Newton iteration, we emulate Algorithm 5.4 from the book: for each system of equations, we would begin with an initial guess x 0 , solve the system Jf (xk)sk = −f (xk) for sk, set xk+1 = xk + sk, and repeat until we reach the desired accuracy. For each part of the problem, the function f is just the LHS minus the RHS (we want f (x) = 0, so we move any constants from the RHS to the LHS; this has no effect on the Jacobian, but will affect evaluations of the function f ). The Jacobian for each part is as follows.

Part (a) J =

 2 x^1 2 x^2 2 x 1 − 1

Part (b) J =

 2 x^1 +^ x^32 3 x^1 x^22 6 x 1 x 2 3(x^21 − x^22 )

Part (c) J =

 1 −^2 x^2 1 −^2 x^1 2 x 1 − 2 2 x 2 + 2

Part (d) J =

 3 x^21 −^2 x^2 1 + 2x 1 x 2 x^21

Part (e) J =

 2 cos(x^1 )^ −^5 −^ sin(x^2 ) −4 sin(x 1 ) 2 cos(x 2 ) − 5

Problem 5

We can just modify the provided code for a 2 × 2 system to accommodate a 3 × 3 system: our Jacobian is now a slightly larger matrix, and our starting guess has to be a 3-vector. And, of course, we have to ensure we change the functions to match the ones in this problem. You should end up with a root of x ≈ [. 8779657602742 ,. 6767569705178 , 1 .330855411621]T^. Here’s what the code might look like.

1 % script to solve the nonlinear system 2 % 3 % 16x1ˆ4+16x2ˆ4+x3ˆ4-16 = 0 4 % x1ˆ2+x2ˆ2+x3ˆ2-3 = 0 5 % x1ˆ3-x2 = 0 6 % 7 % using Newton's method. Use starting value x=[1; 1; 1]. 8 9 tol=1.e-12; % tolerance for stopping 10 kMax=10; % maximum number of iterations allowed 11 12 x=[1;1;1]; % initial guess 13 for k=1:kMax 14 J=[64x(1)ˆ3, 64x(2)ˆ3, 4x(3)ˆ3; 15 2x(1), 2x(2), 2x(3); 16 3x(1)ˆ2, -1, 0]; % Jacobian matrix 17 F=[16x(1)ˆ4+16x(2)ˆ4+x(3)ˆ4-16; 18 x(1)ˆ2+x(2)ˆ2+x(3)ˆ2-3; 19 x(1)ˆ3-x(2)]; % right-hand-side vector 20 dx=J\F; % solve Jdx = F