FENG345_lec4
FENG345_lec4
Engineers I
Lecture 4
2
Introduction
• The open methods require only a single starting value or two starting
values that do not necessarily bracket the root.
• When the open methods converge
they usually do so much more
quickly than the bisection method.
3
Simple Fixed-point Iteration
• Open methods employ a formula to predict the root.
• Such a formula can be developed for simple fixed-point iteration by
rearranging the function 𝑓(𝑥) = 0 so that 𝑥 is on the left-hand side of
the equation:
• the approximate error for this equation can be determined using the
error estimator:
4
Example 1
• Use simple fixed-point iteration to locate the root of 𝑓 𝑥 = 𝑒 −𝑥 − 𝑥.
Solution: The function can be separated directly
5
each iteration brings the estimate closer to the true value of the root: 0.56714329.
Example
• The concepts of convergence and divergence can be depicted graphically.
• pair of equations 𝑦1 = 𝑥 and 𝑦2 = 𝑔 𝑥 .
• These two equations can then be plotted separately.
For the function 𝑓 𝑥 = 𝑒 −𝑥 − 𝑥 ,
and
6
Example
• If |𝑔′ | < 1, the errors decrease with
each iteration. For |𝑔′ | > 1 the errors
grow.
• convergence occurs when |𝑔′ | < 1.
(a) and (b) convergence and (c) and (d) divergence of simple
fixed-point iteration. 7
NEWTON-RAPHSON
• Perhaps the most widely used of all root-locating formulas is the
Newton-Raphson method.
• If the initial guess at the root is 𝑥𝑖 , a tangent
can be extended from the point 𝑥𝑖 , 𝑓 𝑥𝑖 .
• The point where this tangent crosses the x
axis usually represents an improved estimate
of the root.
8
NEWTON-RAPHSON
• the first derivative at x is equivalent to the
slope:
9
Example 2
• Use the Newton-Raphson method to estimate the root of 𝑓 𝑥 = 𝑒 −𝑥 − 𝑥
employing an initial guess of 𝑥0 = 0.
Solution:
Then,
11
Example
• The first iteration flings the solution far away from the initial guess to a new
value (x = 51.65) where f (x) has an extremely high value.
12
Example
• There is no general convergence criterion for Newton-Raphson. Its
convergence depends on the nature of the function and on the accuracy of
the initial guess.
13
SECANT METHODS
• A potential problem in implementing the Newton-Raphson method is the
evaluation of the derivative.
• Although this is not inconvenient for polynomials and many other
functions, there are certain functions whose derivatives may be difficult
or inconvenient to evaluate.
• For these cases, the derivative can be approximated by a backward finite
divided difference:
14
SECANT METHODS
• Then
This is the formula for the secant method. Notice that the approach
requires two initial estimates of x.
15
Non-linear algebraic equations. Newton-Raphson method.
f (x) 0 f (a ) f
Taylor series : f ( x ) f (a ) ( x a ) ... 0 f f x n 1 x n
f
İ
1
Example 4.1 2 sin u u a) Find u. b) Write a MatLAB program to find u.
f (u ) u 2 sin u 0 f ( x ) x 2 sin x 0
df 1
Solution: a) 1 cos( x )
dx x
0.6829
f (1) 1 2 sin 1 0.6829
1 1 1.4856
Initial guess x1=1 f (1) 1 cos( 1) 0.4597
1 0.4597
x2=1+1.4856=2.4856 f (2.4856) 2.4856 2 sin 2.4856 0.4856
0.4856
f (2.4856) 1
1
cos( 2.4856 ) 1.0091 2 0.4812
2.4856 1.0091
% nr1.m
clc,clear,close all
x=1;xe=[0.001];niter=20;kerr=1; ans = 0 4.0000 -0.0001 1.9724
for n=1:1:niter;
f=x-2*sin(sqrt(x)); fd=1-(1/sqrt(x))*cos(sqrt(x));
eps=-f/fd; x=x+eps; if abs(eps)<xe;kerr=0;break;end
end
[kerr,n,eps,x]
Example 4.2
Example 4.3 2u 4.1sin(3v) 3 2 v 3u 2 10.5 Write a MatLAB program to find u and v.
% nr.m
f1 2 x1 4.1sin(3x 2 ) 3 0 clc, clear,close all
x=[-1;3];xe=[0.001;0.001];niter=20;kerr=1;
f 2 3x12 2 x 2 10.5 0
%------------------
Error equations : for n=1:1:niter;
%------------------
2 4.1(3) cos(3x 2 ) 1 f1 b=[2*x(1)-4.1*sin(3*x(2))+3;3*x(1)^2+2*x(2)-10.5];b=-b;
6 x
1 2
2 2 f a=[2,-4.1*3*cos(3*x(2));6*x(1),2];
%------------------
eps=inv(a)*b;x=x+eps;if abs(eps)<xe;kerr=0;break;end
end
x1 1.1993, x 2 3.0925
[kerr,n],[eps,x]
Home Excercise 4.1
u 2 u 2
1.5 (e e ) (e e )
u u
df 1
3.13 tanh u ( x ) 6.26 x (3.13) x ans = 144.93259626492792335739068221301
dx x (e u e u ) 2
Home Excercise 4.2 9.81
Solution: 1 90(tan 0 ) (8100) 1.8
(2)(900) cos 2 0
44.145
f 90(tan x ) 0.8 0
cos 2 x
90 2 sin x cos x
f 44.145
cos 2 x cos 4 x
th0=0:1:80;x=th0*pi/180;f=90*tan(x)-44.145./(cos(x)).^2+0.8;plot (x,f)
nr1.m
clc,clear,close all
x=30*pi/180;xe=[0.001];niter=20;kerr=1;
for n=1:1:niter;
f=90*tan(x)-44.145/(cos(x))^2+0.8;
fd=90/(cos(x))^2-2*44.145*sin(x)*cos(x)/(cos(x))^4;
eps=-f/fd; x=x+eps; if abs(eps)<xe;kerr=0;break;end
end
[kerr,n,eps,x*180/pi]