Bisection method - PowerPoint PPT Presentation

About This Presentation
Title:

Bisection method

Description:

PowerPoint – PowerPoint PPT presentation

Number of Views:229
Avg rating:3.0/5.0
Slides: 17
Provided by: p94
Learn more at: https://math.unm.edu
Category:
Tags: bisection | math | method

less

Transcript and Presenter's Notes

Title: Bisection method


1
Lecture 3 Bisection method
Download bisection02.m And ftest2.m From
math.unm.edu/plushnik/375
2
Bisection method to find roots for function
ftest2 istep0set initial number of steps to
zero a0.1 initial value for interval
(a,b) b2 initial value for interval (a,b) if
sign(ftest2(a)ftest2(b))gt0
error('sign(ftest2(a)ftest2(b))gt0') end
abserr10(-15) stop criterion - desired
absolute error while abs(ftest2((ab)/2))gtabserr
c(ab)/2 calculate midpoint
istepistep1 fcftest2(c) if fc0
break if c is solution then exit end
if (ftest2(a)fc)lt0 bc else
ac end disp('f(c)',num2str(fc),'
x',num2str(c,10))display value of function
f(x) end disp('number of steps for Bisection
algorithm',num2str(istep))
3
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
4
gtgt bisection02 f(c)6.2162 x1.05 f(c)0.73319
x0.575 f(c)-0.69847 x0.3375 f(c)-0.053209
x0.45625 f(c)0.32019 x0.515625 f(c)-2.220
4e-015 x0.465080868 f(c)1.8652e-014
x0.465080868 f(c)7.9936e-015
x0.465080868 f(c)3.1086e-015
x0.465080868 number of steps for Bisection
algorithm51
5
It is often good idea to plot function first
6
Inclass1
Modify bisection02.m and ftest2.m to find root of
e(-x)-x0 at 0.2,1.5
7
Newtons method
Download newton02.m And ftest2.m From
math.unm.edu/plushnik/375
8
Newton's method to find roots for function
ftest x00.5 starting point abserr10(-15)
stop criterion - desired absolute
error istep0 xx0 set initial value of x to
x0 main loop to find root disp('Iterations by
Newton Method') while abs(ftest2(x))gtabserr
istepistep1 f,fderftest2(x)
disp('f(x)',num2str(f),' x',num2str(x,15))d
isplay value of function f(x)
xx-f/fder end f,fderftest2(x)
disp('f(x)',num2str(f),' x',num2str(x,15))d
isplay value of function f(x) disp('number of
steps for Newton algorithm',num2str(istep))
9
gtgt newton02 Iterations by Newton
Method f(x)0.21828 x0.5 f(x)0.0061135
x0.466087210490891 f(x)5.1326e-006
x0.46508171356867 f(x)3.6251e-012
x0.465080867976624 f(x)-4.4409e-016
x0.465080867976026 number of steps for Newton
algorithm4
10
Inclass2
Modify newton02.m and ftest2.m to find root of
e(-x)-x0 by Newtons method starting at x0.6
11
Secant method
Download secant02.m And ftest2.m From
math.unm.edu/plushnik/375
12
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))
13
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
14
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
15
Inclass3
Modify secant02.m and ftest2.m to find root of
e(-x)-x0 by secant method starting at x0.2 and
x1.5
16
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
Write a Comment
User Comments (0)
About PowerShow.com