Chapter 3 Roots of Equations

Download Report

Transcript Chapter 3 Roots of Equations

Chapter 3
Roots of Equations
Objectives
•Understanding what roots problems are and where
they occur in engineering and science
•Knowing how to determine a root graphically
•Knowing how to solve a root problem with
bracketing method
•Understand the open method and recognize the
difference between the open and bracketing
methods
•Knowing how to use MATLAB built-in function
Content
•Introduction
•Graphical method
•Bracketing method (Bisection and false position)
•Open method (Newton Raphson and secant
methods)
•MATLAB built-in function
•Conclusion
Introduction
Many engineering and science problems predict
dependent variable(s) as a function of
independent variables
Heat balance : time
: time&space
Mass balance : mass concen. : time&space
Kirchoff’s law: current/voltage : time
Introduction (cont’d)
See the previous assignment you encountered
What is the ground velocity ?
1 km
t=0, v = 0;
Says that u know the velocity

gm
v(t ) 
1  e ( c / m )t
c

Introduction (cont’d)

from
gm
( c / m )t
v(t ) 
1 e
c
Find the distant
t





gm
( c / m ) t
s(t )   vdt  
1 e
dt
c
0
hence
gm  m ( c / m )t

s(t ) 
1 
t  e
c 
c

Find t1km that s = 1000 m from


gm 
m ( c / m ) t1km

1000 
1 
 t1km  e
c 
c

Introduction (cont’d)
So solve t1km from


gm 
m ( c / m ) t1km

1000 
1 
 t1km  e
c 
c

Can u solve the above equation for t1km ?
Of course, the equation is nonlinear and t1km is an implicit
variable !!
Introduction (cont’d)
If we are solving a simple nonlinear
equation, it’s piece of cake.
2

b

b
 4ac
2
ax  bx  c  0  x 
2a
But what about these
ax 5  bx 4  cx 3  dx 2  ex  f  0  x  ?
sin x  x  0  x  ?
Yes, it’s time for numerical methods !!!
Introduction (cont’d)
Nonlinear Equation
Solvers
Bracketing
Graphical
Bisection
False Position
(Regula-Falsi)
Open Methods
Newton Raphson
Secant
All Iterative
Graphical…
Graphical method means that we plot graph from
the target nonlinear equation and observe the zero
of it !!
Very simple but too iterative.
Here try with parachutist problem…..
Graphical… (cont’d)
Start with the distant equation
gm 
m ( c / m ) t1km

1000 
1 
 t1km  e
c 
c

Find t1km such that




gm 
m ( c / m )t1km

f (t1km ) 
 1   1000  0
 t1km  e
c 
c

is satisfied.
Plot f(t1km) from t1km = {0,T} make sure that the zero of
f(t1km) falls within this interval.
Graphical… (cont’d)
Try with MATLAB to plot the function from t=0,..,50
Utilize the command “inline”
3500
3000
2500
2000
1500
f(x)
zero
1000
Around 12.7, more
accurate result can
attained if u zoom
in the figure !!
500
0
-500
-1000
0
5
10
15
20
25
time (s)
30
35
40
45
50
Bisection
Bracketing…
Sometimes called two-point method
Underline principle
Root of f (x) is bounded by
{xL,xU} where
f(xL)f(xU) < 0
Bisection (cont’d)
How many iterations will it take?
 After 2 iterations
Δx0=b-a
εa(1)=Δx0/2
εa(2) =Δx0/4
 After k iterations
εa(n) =Δx0/2n
 Length of the first Interval
 After 1 iteration
n  log 2 (
x 0
s
)
a  s
Bracketing:Bisection
For the arbitrary equation of one variable, f(x)=0
1. Pick xl and xu such that they bound the root of interest,
check if f(xl).f(xu) <0.
2.
Estimate the root by evaluating f[(xl+xu)/2].
3.
Find the pair
•
If f(xl). f[(xl+xu)/2]<0, root lies in the lower interval, then
xu=(xl+xu)/2 and go to step 2.
Bisection (cont’d)
•
If f(xl). f[(xl+xu)/2]>0, root
lies in the upper interval, then
xl= [(xl+xu)/2, go to step 2.
•
If f(xl). f[(xl+xu)/2]=0, then
root is (xl+xu)/2 and
terminate.
4.
Compare s with a
5.
If a< s, stop. Otherwise
repeat the process.
x 0
  n
2
n
a
Bisection (cont’d)
Bisection (cont’d)
Bisection (cont’d)
Evaluation of Method
Pros
 Easy
 Always find root
 Number of iterations
required to attain an
absolute error can be
computed a priori.
Cons
 Slow
 Know a and b that bound
root
 Multiple roots
 No account is taken of
f(xl) and f(xu), if f(xl) is
closer to zero, it is likely
that root is closer to xl .
Bisection (cont’d)
 If the absolute magnitude of the error εs = 1e-4
x 0
  n
2
n
a
and Lo=2, how many iterations will you have to do to
get the required accuracy in the solution?
n  log 2 (
x 0
s
)
2
n  log 2 ( 4 )  14.3
10
a  s
a  s
Try with simple example : f=sin(10x)+cos(3x) [x=3.7,3.9] es = 10-5
Bisection (cont’d)
MATLAB: Try with the parachutist problem in Chapter 1


gm 
m ( c / m ) t1km

1000 
1 
 t1km  e
c 
c

Find t1km for m = 68.1 kg, c = 12.5 kg/s given that
L0 = 60s and εs = 10-4
Plot approximation error and true error
False position
 If a real root is bounded
by xl and xu of f(x)=0,
then we can approximate
the solution by doing a
linear
interpolation
between the points
[xl, f(xl)] and [xu, f(xu)]
to find the xr value such
that l(xr)=0, where l(x) is
the linear approximation
of f(x).
False position (cont’d)
Procedure
1.
2.
Find a pair of values of x, xl and xu such that
fl=f(xl) <0 and fu=f(xu) >0.
Estimate the value of the root from the
following formula
xl f u  xu f l
xr 
fu  fl
and evaluate f(xr).
False position (cont’d)
Procedure (cont’d)
3.
Use the new point to replace one of the original points,
keeping the two points on opposite sides of the x axis.
If f(xr)<0 then xl=xr
== > fl=f(xr)
If f(xr)>0 then xu=xr
== > fu=f(xr)
If f(xr)=0 then you have found the root and need go no
further!
False position (cont’d)
Procedure (cont’d)
4.
See if the new xl and xu are close enough for
convergence to be declared. If they are not go back
to step 2.
Now u may wonder how good of this technique is?
Comparing with the bisection method, which one is
better ?
I would like u try this method with parachutist problem.
False position… (cont’d)

Why this method?


Faster
Always converges for a single root.
Pitfalls of the False-Position Method.
Method applied to some curvature functions may slowly
converge.
Open methods
 Open methods are
based on formulas
that require only a
single starting
value of x or two
starting values
that do not
necessarily
bracket the root.
Fixed-point…(cont’d)
•Rearrange the function so that x is on
the left side of the equation:
f ( x)  0 
xk  g ( xk 1 )
g ( x)  x
xo given , k  1, 2, ...
•Bracketing methods are “convergent”.
•Fixed-point methods may sometime
“diverge”, depending on the stating point
(initial guess) and how the function
behaves.
Fixed-point…(cont’d)
Convergence
 x=g(x) can be expressed
as a pair of equations:
y1=x
y2=g(x) (component
equations)
 Plot them separately.
Fixed-point…(cont’d)
 Fixed-point iteration converges if
g ( x)  1
(slope of the line f(x)  x)
•When the method converges, the error is
roughly proportional to or less than the
error of the previous step, therefore it is
called “linearly convergent.”
Fixed-point…(cont’d)
Example
f ( x)  x 2  x  2
Rearrange x = g(x)
g ( x)  x 2  2
or
g ( x)  x  2
or
2
g ( x)  1 
x

x0
Newton-Raphson
 Most widely used method.
 Based on Taylor series expansion:
x 2
f ( xi 1 )  f ( xi )  f ( xi )x  f ( xi )
 Ox 3
2!
The root is the value of x i 1 when f(x i 1 )  0
Rearrangin g,
Solve for
0  f(xi )  f (xi )( xi 1  xi )
f ( xi )
xi 1  xi 
f ( xi )
Newton-Raphson
formula
Newton-Raphson… (cont’d)
 A convenient method for
functions whose
derivatives can be
evaluated analytically. It
may not be convenient
for functions whose
derivatives cannot be
evaluated analytically.
Newton-Raphson… (cont’d)
Secant method
 A slight variation of Newton’s method for functions
whose derivatives are difficult to evaluate. For these
cases the derivative can be approximated by a backward
finite divided difference.
xi  xi 1
f ( xi ) 
f ( xi )  f ( xi 1 )
xi  xi 1
xi 1  xi  f ( xi )
f ( xi )  f ( xi 1 )
i  1,2,3, 
Secant method(cont’d)
• Requires two initial
estimates of x , e.g, xo,
x1. However, because f(x)
is not required to change
signs between estimates,
it is not classified as a
“bracketing” method.
• The scant method has the
same properties as
Newton’s method.
Convergence is not
guaranteed for all xo, f(x).
Secant method(cont’d)