










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!











Math 433 - Numerical Analysis - Spring 2008 Homework 4: SOLUTIONS Assigned: Friday, February 1, 2008. Due: Friday, February 8, 2008.
BOOK PROBLEMS: # 11 pg. 113
α − xn+ α − xn
α − xn α − xn− 1
or equivalently (α − xn+1)(α − xn− 1 ) ≈ (α − xn)^2. One can then solve this expression for α to get an improved approximation for the fixed point. If the assumption g′(xn) ≈ constant is true, the approximation for α that is obtained in this way is usually a big improvement over the last xn in the generated sequence. This procedure is called Aitken’s extrapolation. Given below is a table of iterates from a linearly convergent sequence xn+1 = g(xn) = xn − (x^2 n − 3)/ 2 used to find
n xn 0 1. 8000000000 1 1. 6800000000 2 1. 7688000000 3 1. 7044732800 4 1. 7518586988 5 1. 7173542484 6 1. 7427014411 7 1. 7241972846 8 1. 7377691464 9 1. 7278483432
Compare the absolute error in x 9 to that of the new approximate root found using the Aitken’s extrapolation procedure above.
In our analysis of Newton’s method we showed that if f ′(α) 6 = 0 (i.e. α is a simple root), then second order convergence results. However, if α is a multiple root of f (x) of multiplicity p then
f (α) = f ′(α) = f ′′(α) = ... = f (p−1)(α) = 0.
In this case, we can write
f (x) = (x − α)ph(x)
for some function h(x), and h(α) 6 = 0.
(a) Write out the iteration function g(x) for Newton’s method in this case (note: it will involve h(x) and h′(x)). (b) Show that g′(α) = 1 − 1 /p 6 = 0, implying only linear convergence of New- ton’s method in the case of multiple roots. (c) Verify the theory developed above by applying Newton’s method to f (x) = (x − 1)^5 cos x, with an initial guess near x = 1 (thus, we are interested in finding the multiple root α = 1). Then use the iterates to determine both the order of convergence (which should be ≈ 1), as well as the linear convergence rate, which should approach that predicted in (b) above.
disp([’Initial guesses: p(0)=’,num2str(p0), ’, p(1)=’,num2str(p1)])
for k=1:max p2=p1-feval(’f’,p1)(p1-p0)/(feval(’f’,p1)-feval(’f’,p0)); err=abs(p2-p1); relerr=2err/(abs(p2)+delta);
error_new=abs(p2-pex); error_old=abs(p1-pex); order=log(error_new)/log(error_old);
disp([’p(’,num2str(k+1),’)=’,num2str(p2),’ order r=’,num2str(order)])
p0=p1; p1=p2; y=feval(’f’,p1); if (err> secant Initial guesses: p(0)=-1, p(1)= p(2)=-0.23658 order r=-2. p(3)=-0.17134 order r=1. p(4)=-0.01832 order r=2. p(5)=0.062597 order r=0. p(6)=0.13198 order r=0. p(7)=0.18129 order r=0. p(8)=0.21903 order r=0. p(9)=0.24716 order r=0. p(10)=0.2684 order r=0. p(11)=0.28436 order r=0. p(12)=0.2964 order r=0.
p(13)=0.30547 order r=0. p(14)=0.31231 order r=0. p(15)=0.31747 order r=0. p(16)=0.32136 order r=0. p(17)=0.3243 order r=0. p(18)=0.32651 order r=0. p(19)=0.32819 order r=0. p(20)=0.32945 order r=0. p(21)=0.3304 order r=0.
Root is p=0. Stopping tolerance is 1e- max # of iterations is 30
x = 1/3 is a triple root of f (x). Convergence is slightly slower than in the previous case when we had a double root at x = 0, but convergence is still linear since r ≈ 0 .99.
(c) f (x) = y =
x 1 + x^2
( 1 −
21 x 125
) has a zero at x = 2. 5
>> secant Initial guesses: p(0)=-1, p(1)= p(2)=1.9869 order r=0. p(3)=2.2574 order r=1. p(4)=2.3377 order r=1. p(5)=2.4029 order r=1. p(6)=2.4392 order r=1. p(7)=2.4626 order r=1. p(8)=2.4768 order r=1. p(9)=2.4857 order r=1.
Root is p=2. Stopping tolerance is 1e- max # of iterations is 30
x = 2.5 is a double root of f (x). Since r ≈ 1, we have again only linear conver- gence.
Problem # 14 pg. 125
(a) f (x) = 1 + ln x − x has a zero at x = 1
>> secant Initial guesses: p(0)=1.5, p(1)= p(2)=1.0704 order r=0. p(3)=1.0125 order r=0.
Again, convergence is slightly faster with using f /f ′^ than with just f but still linear since r ≈ 1.
function y=f(x)
%yf=1+log(x)-x; %yder=1/x-1;
%yf=27x^4+162x^3-180x^2+62x-7; %yder=108x^3+486x^2-360*x+62;
yf=x/(1+x^2)-500/841(1-21x/125); yder=1/(1+x^2)-2*x^2/(1+x^2)^2+84/841;
y=yf/yder;
Problem # 15 pg. 125
(a) f (x) = 1 + ln x − x has a zero at x = 1
>> secant_modified Initial guesses: p(0)=1.5, p(1)= p(2)=0.55475 order r=-0.85009 constant C=0. p(3)=-2.0008 order r=-1.177 constant C=5. p(4)=2.9954+0.093976i order r=1.5826 constant C=0. p(5)=1.602+0.89327i order r=0.55268 constant C=0. p(6)=1.3888-0.37868i order r=0.60054 constant C=0. p(7)=1.3948+0.21762i order r=0.94645 constant C=0. p(8)=1.1178-0.24676i order r=0.39203 constant C=0. p(9)=1.2555+0.046235i order r=1.6883 constant C=1. p(10)=1.0239-0.16822i order r=0.16199 constant C=0. p(11)=1.1703-0.021452i order r=4.2578 constant C=1. p(12)=0.98127-0.11547i order r=-0.076426 constant C=0. p(13)=1.111-0.051506i order r=-8.8415 constant C=1. p(14)=0.96098-0.07614i order r=-0.34483 constant C=0. p(15)=1.0666-0.062837i order r=-1.8043 constant C=1. p(16)=0.95322-0.04522i order r=-0.70705 constant C=0. p(17)=1.0323-0.062802i order r=-0.71858 constant C=1. p(18)=0.95369-0.020744i order r=-1.4033 constant C=0. p(19)=1.0065-0.055162i order r=-0.16831 constant C=1. p(20)=0.95989-0.0021864i order r=-5.1548 constant C=0. p(21)=0.98863-0.042644i order r=0.25665 constant C=1. p(22)=0.96973+0.010399i order r=2.9204 constant C=0. p(23)=0.97858-0.027886i order r=0.69264 constant C=1. p(24)=0.98104+0.017049i order r=0.89345 constant C=1.
There is no convergence even though approximations are around solution x = 1. They also become complex valued at the third step. The absence of convergence can be seen also from values of numerically approximated order r. There is no limit- ing value of r, some values of positive, some are negative, magnitude changes quite
p(31)=-180506278.5588 order r=1.
Root is p=-180506278. Stopping tolerance is 1e- max # of iterations is 30
Method also diverges.
function [p1,err,k,y]=secant(f,p0,p1,delta,epsilon,max1)
%Input - f is the object function input as a string ’f’ % - p0 and p1 are the initial approximations to a zero of f % - delta is the tolerance for p % - epsilon is the tolerance for the function values y % - max1 is the maximum number of iterations %Output - p1 is the secant method approximation to the zero % - err is the error estimate for p % - k is the number of iterations % - y is the function value f(p1)
p0=1.5; p1=2; delta=1e-5; epsilon=1e-5; max1=30; pex=0; m=2; % multiplicity of a root rg=(1+sqrt(5))/2; % golden ratio - order of convergence of secant % method for a simple root
disp([’Initial guesses: p(0)=’,num2str(p0), ’, p(1)=’,num2str(p1)])
for k=1:max p2=p1-mfeval(’f’,p1)(p1-p0)/(feval(’f’,p1)-feval(’f’,p0)); err=abs(p2-p1); relerr=2*err/(abs(p2)+delta);
error_new=abs(p2-pex); error_old=abs(p1-pex); order=log(error_new)/log(error_old); const=error_new/error_old^rg;
disp([’p(’,num2str(k+1),’)=’,num2str(p2),’ order r=’,num2str(order), ... ’ constant C=’,num2str(const)])
p0=p1; p1=p2; y=feval(’f’,p1);
if (err Problem 1.
clear all
n=8;
x(n-1)=1.7241972846; x(n)=1.7377691464; x(n+1)=1.7278483432; alpha_Ait=(x(n)^2-x(n-1)x(n+1))/(2x(n)-x(n+1)-x(n-1));
alpha_ex=sqrt(3);
error9=abs(x(n+1)-alpha_ex); error_Ait=abs(alpha_Ait-alpha_ex);
disp([’alpha_Ait=’,num2str(alpha_Ait,’%2.8f’), ... ’, error(9)=’,num2str(error9,’%2.8f’), ... ’, error_Ait=’,num2str(error_Ait,’%2.8f’)])
>> Aitken_error alpha_Ait=1.73203784, error(9)=0.00420246, error_Ait=0.
Clearly, error errorAit = 0.00001297 in the approximation using Aitken’s accel- eration is smaller than the error error(9) = 0.00420246 in the original fixed point iterations.
p(41)=1.000028863302157, order r=1.0218, asymp_const=0. p(42)=1.000023090589824, order r=1.0213, asymp_const=0. p(43)=1.000018472438642, order r=1.0209, asymp_const=0. p(44)=1.000014777929655, order r=1.0205, asymp_const=0. p(45)=1.000011822330119, order r=1.0201, asymp_const=0. p(46)=1.000009457855388, order r=1.0197, asymp_const=0. p(47)=1.000007566278738, order r=1.0193, asymp_const=0. p(48)=1.000006053019424, order r=1.0189, asymp_const=0. p(49)=1.000004842413256, order r=1.0186, asymp_const=0. p(50)=1.000003873929144, order r=1.0182, asymp_const=0. root is p=1. number of iterations is 50 error between successive approximations is 9.6848e- value of function f at the approximation to root p is 4.714e-
As can be seen from results, iterations approach the root x = 1 with linear con- vergence since ln ln^ en e+1n ≈ 1. The rate of this linear convergence, i.e. the asymptotic constant is approximately 0.8, which is in the agreement with theoretical prediction 1 − 1 /5 = 0.8. An initial guess should be taken with care since there is another root at 1.5708. We used p 0 = 1. 4
function [p0,err,k,y]=newton(f,df,p0,delta,epsilon,max1)
%Input - f is the object function input as a string ’f’ % - df is the derivative of f input as a string ’df’ % - p0 is the initial approximation to a zero of f % - delta is the tolerance for p % - epsilon is the tolerance for the function values y % - max1 is the maximum number of iterations %Output - p0 is the Newton-Raphson approximation to the zero % - err is the error estimate for p % - k is the number of iterations % - y is the function value f(p0)
clear all p0=1.4; pex=1; asympt_const_true=1-1/5; disp([’true asympt constant = 1-1/5=’, num2str(asympt_const_true)])
delta=1E-9; epsilon=1E-10; max1=50;
disp([’initial guess p0=’,num2str(p0)])
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
!0.
!0.
!0.
!0.
!0.
0
x
f
Graph of f(x)=(x!1)^5 *cos(x)=
for k=1:max p1=p0-feval(’f’,p0)/feval(’df’,p0); err_new=abs(p1-pex); err_old=abs(p0-pex); order=log(err_new)/log(err_old); err=abs(p1-p0); relerr=2*err/(abs(p1)+delta); asymp_const=err_new/err_old; p0=p1; disp([’p(’,num2str(k),’)=’,num2str(p1,’%2.15f’), ... ’, order r=’,num2str(order), ... ’, asymp_const=’,num2str(asymp_const)]) y=feval(’f’,p0);