Fixed%20point%20iteration - PowerPoint PPT Presentation

About This Presentation
Title:

Fixed%20point%20iteration

Description:

Fixed point iteration – PowerPoint PPT presentation

Number of Views:70
Avg rating:3.0/5.0
Slides: 17
Provided by: p94
Learn more at: https://math.unm.edu
Category:

less

Transcript and Presenter's Notes

Title: Fixed%20point%20iteration


1
Lecture 5 Fixed point iteration
Download fixedpoint.m From math.unm.edu/plushnik/
375
2
fixedpoint.m - solution of nonlinear equation by
fixed point iterations function x,n, xn
fixedpoint(f, x0, tol, nmax) find the root of
equation xf(x) by fixed point method input
f - inline function x0
- initial guess tol - exit
condition f(x) lt tol nmax - maximum
number of iterations output x
- the approximation for the root n
- number of iterations xn - vector
of apporximations x(iter) compute function
at initial guesses f0 f(x0) n 0
begin iterations while ((abs(f0-x0) gt tol)
(n lt nmax)) x0 f0 f0
f(x0) disp('Error f0-x0',num2str(f0-x0))
if f0 x0 x0 is a root, done
break end n n1 xn(n) x0
end if nnmax disp('warning maximum
iterations reached without conversion') end
xx0 disp('Number of iterations n
',num2str(n)) end
3
Enter inline functions
gtgt g1inline('1-x3') gtgt g2inline('(1-x)(1/3)')
gtgt g3inline('(12x3)/(13x2)')
4
gtgtfixedpoint(g1,0.5,10(-8),10) Error
f0-x0-0.54492 Error f0-x00.63396 Error
f0-x0-0.85998 Error f0-x00.89482 Error
f0-x0-0.9955 Error f0-x00.99662 Error
f0-x0-1 Error f0-x01 Error f0-x0-1 Error
f0-x01 warning maximum iterations reached
without conversion Number of iterations n 10
5
gtgt fixedpoint(g2,0.5,10(-8),100) Error
f0-x0-0.20282 Error f0-x00.15148 Error
f0-x0-0.10605 Error f0-x00.077491 Error
f0-x0-0.054795 Error f0-x00.039626 Error
f0-x0-0.028184 Error f0-x00.020281 Error
f0-x0-0.01447 Error f0-x00.010387 Error
f0-x0-0.0074232 Error f0-x00.0053217 Error
f0-x0-0.0038066 Error f0-x00.0027272 Error
f0-x0-0.0019517 Error f0-x00.0013978 Error
f0-x0-0.0010005 Error f0-x00.00071648 Error
f0-x0-0.00051291 Error f0-x00.00036726 Error
f0-x0-0.00026293 Error f0-x00.00018826 Error
f0-x0-0.00013478 Error f0-x09.6501e-005 Error
f0-x0-6.9091e-005 Error f0-x04.9467e-005 Error
f0-x0-3.5416e-005 Error f0-x02.5357e-005 Error
f0-x0-1.8155e-005 Error f0-x01.2998e-005 Erro
r f0-x0-9.3063e-006 Error f0-x06.663e-006 Erro
r f0-x0-4.7705e-006 Error f0-x03.4155e-006 Err
or f0-x0-2.4454e-006 Error f0-x01.7508e-006 Er
ror f0-x0-1.2535e-006 Error f0-x08.9748e-007 E
rror f0-x0-6.4257e-007 Error
f0-x04.6006e-007 Error f0-x0-3.2938e-007 Error
f0-x02.3583e-007 Error f0-x0-1.6885e-007 Error
f0-x01.2089e-007 Error f0-x0-8.6551e-008 Erro
r f0-x06.1968e-008 Error f0-x0-4.4367e-008 Err
or f0-x03.1765e-008 Error f0-x0-2.2743e-008 Er
ror f0-x01.6283e-008 Error f0-x0-1.1658e-008 E
rror f0-x08.3468e-009 Number of iterations n
52
6
gtgt fixedpoint(g3,0.5,10(-8),100) Error
f0-x0-0.031106 Error f0-x0-0.0008513 Error
f0-x0-6.1948e-007 Error f0-x0-3.2774e-013 Numbe
r of iterations n 4 gtgt
7
Secant method
Download secant02.m And ftest2.m From
math.unm.edu/plushnik/375
8
Secant method to find roots for function
ftest2 x00.1 x12.0starting
points abserr10(-14) stop criterion - desired
absolute error istep0 xn1x0 set initial
value of x to x0 xnx1 main loop to find
root disp('Iterations by Secant Method') while
abs(ftest2(xn))gtabserr istepistep1
fnftest2(xn) fn1ftest2(xn1)
disp('f(x)',num2str(fn),' xn',num2str(xn,15))
display value of function f(x)
xtmpxn-(xn-xn1)fn/(fn-fn1) xn1xn
xnxtmp end fftest2(xn)
disp('f(x)',num2str(fn),' xn',num2str(xn,15))
display value of function f(x) disp('number
of steps for Secant algorithm',num2str(istep))
9
test function is defined at fourth line
derivative of function is defined at firth
line function f,fderivativeftest2(x)
fexp(2x)x-3 fderivative2exp(2x)1
10
gtgt secant02 Iterations by Secant
Method f(x)53.5982 xn2 f(x)-1.4715
xn0.157697583825433 f(x)-1.2804
xn0.206925256821038 f(x)0.46299
xn0.536842578960542 f(x)-0.094954
xn0.449229649271443 f(x)-0.0057052
xn0.464140200867443 f(x)7.5808e-005
xn0.465093357175321 f(x)-5.9571e-008
xn0.465080858161814 f(x)-6.2172e-013
xn0.465080867975924 f(x)-6.2172e-013
xn0.465080867976027 number of steps for Secant
algorithm9 gtgt
11
Inclass3
Modify secant02.m and ftest2.m to find root of
e(-x)-x0 by secant method starting at x0.2 and
x1.5
12
Answer to inclass3
gtgt secant02 Iterations by Secant
Method f(x)-1.2769 xn1.5 f(x)-0.088702
xn0.624324608254261 f(x)0.012856
xn0.558951914931113 f(x)-0.00013183
xn0.567227412711665 f(x)-1.9564e-007
xn0.567143415251049 f(x)2.9781e-012
xn0.567143290407884 f(x)2.9781e-012
xn0.567143290409784 number of steps for Secant
algorithm6
13
Matlab function fzero
X FZERO(FUN,X0), X0 a scalar Attempts to find
a zero of the function FUN near X0. FUN is a
function handle. The value X returned by FZERO
is near a point where FUN changes sign (if FUN
is continuous), or NaN, if the srootfinding search
fails. X FZERO(FUN,X0), X0 a 2-vector.
Assumes that FUN(X0(1)) and FUN(X0(2)) differ in
sign, insuring a root. X FZERO(FUN,X0,OPTIONS).
Solves the equation with default optimization
parameters replaced by values in the string
OPTIONS, an argument created with the OPTIMSET
function.
14
Example of fzero use
gtgt options optimset('disp', 'iter', 'tolx',
1.e-15) gtgt fzero(_at_ftest2,0.1 2,options)
Func-count x f(x)
Procedure 2 0.1 -1.6786
initial 3 0.157698 -1.4715
interpolation 4 0.556708
0.601452 interpolation 5
0.440938 -0.143633 interpolation 6
0.463256 -0.0110609
interpolation 7 0.465084 2.0255e-005
interpolation 8 0.465081
-3.08857e-008 interpolation 9
0.465081 -8.61533e-014 interpolation 10
0.465081 0
interpolation Zero found in the interval 0.1,
2 ans 0.4651 gtgt
15
Inclass4
Modify ftest2.m to find root of e(-x)-x0 by
Brents method starting at x0.2 and x1.5
16
Answer to inclass4
gtgt fzero(_at_ftest2b,0.2 1.5,options)
Func-count x f(x)
Procedure 2 0.2 0.618731
initial 3 0.624325 -0.0887015
interpolation 4 0.571121
-0.0062285 interpolation 5
0.567143 1.13316e-006 interpolation 6
0.567143 -8.15018e-010
interpolation 7 0.567143 -1.11022e-016
interpolation 8 0.567143
-1.11022e-016 interpolation Zero found
in the interval 0.2, 1.5 ans 0.5671
Write a Comment
User Comments (0)
About PowerShow.com