Вы находитесь на странице: 1из 21

f x =

Roots of Equations
- - Graphical Methods Graphical Methods
- - Fixed Fixed- -Point Iteration Point Iteration
- - Bisection Bisection Method Method
- - Newton Newton s Method s Method
- - Secant Method Secant Method
- - Roots of Polynomials Roots of Polynomials
Numerical Methods for Numerical Methods for Civil Civil Engineers Engineers
Mongkol JIRAVACHARADET
S U R A N A R E E INSTITUTE OF ENGINEERING
UNIVERSITY OF TECHNOLOGY SCHOOL OF CIVIL ENGINEERING
Lecture 5
What Are Roots? What Are Roots?
Quadratic formula: f(x) = ax
2
+ bx + c = 0
a
ac b b
x
2
4
2
t

x
f(x)
0
x
1
x
2
Roots = Values of x that make f(x) = 0
GRAPHICAL METHODS GRAPHICAL METHODS
Plot the function and observe where it crosses the x axis.
Example: Throw a Turtle out of a Plane ! Example: Throw a Turtle out of a Plane !
Gravity = mg
Drag = cv
Consider the forces acting on a turtle thrown out from a plane.
According to Newtons law :
dt
dv
m
Net force acting on
the turtle
=
1
where m= is the mass of the turtle (kg),
v = velocity of the turtle (m/s),
t = time (s)
For a turtle in free fall, Net force = mg cv
where c is some coefficient of friction.
cv mg
dt
dv
m 2
t
v
(
t
)
gm/c
Lets now find the solution. Divide Eq. (2) by mgives:
v
m
c
g
dt
dv

,
_



m
ct
e
c
gm
t v 1 ) (
if v = 0 at t = 0
Problem: From the velocity equation of the turtle, find the value of the drag
coefficient c such that a turtle of mass m = 5 can attain a prescribed velocity,
v = 10, at a set period of time, t = 9. Use g = 10.
In the context of the problem mentioned above, m, v, and t are constant
(parameters) of the problem.
The only variable that we can adjust is c.
To solve this problem, rewrite the velocity equation as
) ( 1 ) ( t v e
c
gm
c f
m
ct

,
_



10 1
50
) (
5
9

,
_



c
e
c
c f
So our task of solving the problem reduces to merely finding the value of c,
such that f( c ) =0, for the given values of v, m and t.
Graphical method
.tn++enaan+.naaon.+n f(x) z+.+nra+ann+. f(x) =0nann.+n
oanu x uu:a+ a+:no.eo+:ua+
x
f(x)
Graphical method : NOT precise
ZOOM
ZOOM
Double root?
Bracketing Bracketing Method Method
Coarse level search for roots over large interval
1) Subdividing large interval into smaller subinterval
2) Examine sign at the end of each subinterval
+ + + + + + + + +
- - - - - - - - - -
+ + + +
+ + + + - - - + +
f (x)
x x
1
x
2
Possible ways in an interval Possible ways in an interval
Part (a) and (c) : f(x
l
) and f(x
u
) same sign
No roots or Even number of roots
Part (b) and (d) : f(x
l
) and f(x
u
) different signs
One roots or Odd number of roots
Exceptions: Exceptions:
(a) Multiple roots
(b) Discontinuous function
Bracketing Algorithm
Given: f (x), x
min
, x
max
, n
dx = (x
max
-x
min
)/n % Size of bracket interval
x
a
= x
min
% Initialize left side of test bracket
i = 0 % Initialize counter
while i < n
i = i + 1
x
b
= x
a
+ dx
if f (x
a
) and f (x
b
) have different sign
save [ x
a
, x
b
] for further root finding
end
x
a
= x
b
end
Detecting Sign Change : f (x
a
) &f (x
b
)
1st Solution: f (x
a
) f (x
b
) < 0 ?
>> format long e
>> fa = 1e-120; fb = -2e-300;
>> fa * fb
ans = 0
< realmin
2nd Solution: Use sign function
>> fa = 1e-120; fb = -2e-300;
>> sign(fa) ~= sign(fb)
ans = 1
return true value = 1
0.00
Example: Graphical Methods
Plot the function and observe where it crosses x axis
( )
0.147
667.38
( ) 1 40
x
f x e
x


f(x)
x
4 8 12
16
20
0
-10
20
40
x f(x)
4
8
12
16
20
34.115
17.653
6.067
-2.269
-8.401
Observe: x 15 f (15) = -0.4133
Interpolation (False-position method)
Assume as linear function for short interval
12 16
6.607
2.269
Interpolation:
6.607
12 (16 12) 14.977
6.607 ( 2.269)
x +

f (14.977) = -0.3691
f (15) = -0. 4133, f (14) = 1.582
2nd Interpolation:
1.582
14 (15 14) 14.793
1.582 ( 0.4133)
x +

f (14.793) = -0.013
Open Methods: require only a single starting value of x without bracketing
the root.
Fixed-point iteration
Newton-Raphson method
Secant method
Root Finding Methods Root Finding Methods
Two major classes of methods:
Bracketing methods: start with guesses that bracket, or contain, the root
and then systematically reduce the width of the bracket
Graphical method
False-position method
Bisection method
f(x f(x) = 0 ) = 0
x = ? x = ?
Fixed-Point Iteration
3) Predict new x
i+1
as a function of old x
i
Iterative until satisfy
1
1
100%
i i
a
i
x x
x

+
+


1) Rewrite original equation f(x) = 0 into another formx = g(x).
4) Use iteration x
i+1
= g(x
i
) to find a value that reaches convergence.
x x x x
x
x x x
+
+
+
sin 0 sin
2
3
0 3 2
2
2
Example:
2) Select initial value x
0
x
i+1
= g (x
i
)
Example: Finding root of f (x) = x - e
-x
= 0
1
i
x
i
x e

+

i x
i

a
(%)
0
1
2
3
4
5
6
7
8
9
10
0
1
0.3679
0.6922
0.5005
0.6062
0.5454
0.5796
0.5601
0.5711
0.5649
100
171.8
46.9
38.3
17.4
11.2
5.90
3.48
1.93
1.11
0 1 2 3 4 5 6 7 8 9 10 11 12
0
0.2
0.4
0.6
0.8
1
Number of Iteration
A
p
p
r
o
x
i
m
a
t
e
d

R
o
o
t
True value = 0.5671
>> 0
>> exp(-ans)
0 0.2 0.4 0.6 0.8 1
0
0.2
0.4
0.6
0.8
1
x
Two-Curve Graphical Method
>> x = 0 : 0.1 : 1;
>> plot(x, exp(-x)-x)
>> x = 0 : 0.1 : 1;
>> plot(x, x, x, exp(-x))
( )
x
f x e

( ) f x x
0 0.2 0.4 0.6 0.8 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
x
f
(
x
)

=

e
x
p
(
-
x
)

-

x
Root
( )
x
f x e x


Convergence
0
0 0.2 0.4 0.6 0.8 1
0.2
0.4
0.6
0.8
1
x
y
y
1
= x
y
2
= g(x)
0.3679
0.6922
0.5005
0.6062
Divergence
0
0 0.2 0.4 0.6 0.8 1
0.2
0.4
0.6
0.8
1
x
y
y
1
= x
y
2
= g(x)
x
0
Bisection Method
Repeatedly halve interval while bracketing root
f (x)
x
x
a
x
b
1) Choose interval [ x
a
, x
b
] which has sign-change
+
-
2) Compute midpoint of interval x
m
= ( x
a
+ x
b
) / 2
x
m
+
3) Select subinterval which has sign-change and repeat 2)
-
Example: Use bisection method find the root of equation
( )
0.147
667.38
( ) 1 40
x
f x e
x


f(x)
x
4 8 12
16
20
0
-10
20
40
Initial interval
[ 12 , 16 ]
Estimate root at midpoint:
12 16
14
2
14.7802 14
100% 5.279%
14.7802
r
t
x


True value of the root:
14.7802
f (14) = 1.582 [ 14 , 16 ]
+ -
Select interval with sign-change:
Next estimation: x
r
= (14+16)/2 = 15
15 14
100% 6.667%
14
a



<
s
= 0.5%
Termination Criteria and Error Estimates
Stop computation when
a
<
s
, Ex.
s
= 0.5%
Iteration x
a
x
b
x
r

a
(%)
t
(%)
1
2
3
4
5
6
12
14
14
14.5
14.75
14.75
16
16
15
15
15
14.875
14
15
14.5
14.75
14.875
14.8125
6.667
3.448
1.695
0.840
0.422
5.279
1.487
1.896
0.204
0.641
0.219
Bisection Algorithm
initialize: a = . . . , b = . . .
for k = 1, 2, . . .
x
m
= a + (b-a)/2
if sign(f (x
m
)) = sign(f (a))
a = x
m
else
b = x
m
end
if converged, stop
end
less susceptible to
roundoff error than
(a+b)/2
Example: Apply Bisection to x - x
1/3
- 2 = 0
bisect.m
function xm = bisect(a, b, n)
if nargin<3, n=15; end % Default number of iterations
fa = a - a^(1/3) - 2; % Initial value of f(a) and f(b)
fb = b - b^(1/3) - 2;
fprintf( k a xmid b f(xmid)\n);
for k = 1:n
xm = a + 0.5*(b-a); % Computing midpoint
fm = xm - xm^(1/3) - 2; % Function value at midpoint
fprintf(%3d %12.8f %12.8f %12.8f %12.3e\n, k, a, xm, b, fm);
if sign(fm) == sign(fa) % Root lies in [xm, b] replace a
a = xm;
fa = fm;
else % Root lies in [xm, a] replace b
b = xm;
fb = fm;
end
end
Newtons Method
First-order Taylor series:
1 1
( ) ( ) ( )( )
i i i i i
f x f x f x x x
+ +

+
1 1
( )
Set ( ) 0
( )
i
i i i
i
f x
f x x x
f x
+ +

f(x
i
)
x
i
x
i+1
1
( )
( )
i
i i
i
f x
x x
f x
+

slope = f(x)
f(x)
Root
x
x
1
f(x
1
)
Approximation Sequence of Newtons Method
f(x)
x x
3
x
2
f(x
2
)
Failure of Newtons Method
Case 1: Inflection point in vicinity of root
f(x)
x
x
1
x
2
x
3
Failure of Newtons Method
Case 2: Oscillate around local maximum or minimum
f(x)
x
Failure of Newtons Method
Case 3: Jump away for several roots
f(x)
x
Failure of Newtons Method
Case 4: Disaster from zero slope
f(x)
x
Example: Apply Newtons Method to x - x
1/3
- 2 = 0
newton.m
function x = newton(x0, n)
if nargin<2, n=5; end % Default number of iterations
x = x0; % Initial guess
fprintf( k f(x) dfdx x(k+1)\n);
for k = 1:n
f = x - x.^(1/3) - 2; % Function value
dfdx = 1 - (1/3)*x.^(-2/3); % Derivative value
x = x - f/dfdx;
fprintf(%3d %12.3e %12.3e %18.15f\n, k-1, f, dfdx, x);
end
Secant Method
for function whose derivatives are difficult to evaluate
Derivative approximated by backward finite difference
( )
( ) ( )
1
1
i i
i
i i
f x f x
f x
x x

1
( )
( )
i
i i
i
f x
x x
f x
+

( )
1
1
1
( )
( ) ( )
i i i
i i
i i
f x x x
x x
f x f x

f(x
i
)
x
i
x
i-1
x
f(x
i-1
)
Example: Use secant method to estimate root of e
-x
- x = 0
Initial estimate x
-1
= 0 and x
0
= 1.0
True root = 0.56714329. . .
First iteration:
x
-1
= 0 f (x
-1
) = 1.00000
x
0
= 1 f (x
0
) = -0.63212
1
0.63212(0 1)
1 0.61270 8.0%
1 ( 0.63212)
t
x



Second iteration:
x
0
= 1 f (x
0
) = -0.63212
x
1
= 0.61270 f (x
1
) = -0.07081
2
0.07081(1 0.61270)
0.61270 0.56384 0.58%
0.63212 ( 0.07081)
t
x



Third iteration:
x
1
= 0.61270 f (x
1
) = -0.07081
x
2
= 0.56384 f (x
2
) = 0.00518
3
0.00518(0.61270 0.56384)
0.56384 0.56717
0.07081 ( 0.00518)
0.0048%
t
x

Roots of Polynomials
2
0 1 2
( )
n
n n
f x a a x a x a x + + + + L
n = order of polynomial
as = constant coefficients
where
Roots of polynomials:
(1) nth-order equation has n real or complex roots
(2) If n is odd, at least one root is real.
(3) Complex roots exist with conjugate pairs ( + i and i)
Ordinary Differential Equation (ODE)
2
2 1 0
2
( )
d y dy
a a a y F t
dt dt
+ +
General Solution:
2
2 1 0
2
0
d y dy
a a a y
dt dt
+ +
2
2 1 0
Set 0
rt rt rt rt
y e a r e a re a e + +
2
2 1 0
Canceling exponents 0 a r a r a + +
Characteristic equation
Characteristic Equation
2
2 1 0
0 a r a r a + +
Roots of equation by quadratic formula
2
1 1 1 2 0
2 2
4
2
r a a a a
r a
t

EIGENVALUES
(1) If a
1
2
- 4a
2
a
0
> 0, roots are real
1 2
1 2
r t r t
y c e c e +
y
t
Overdampedcase
(2) If a
1
2
- 4a
2
a
0
= 0, single root is real
( )
1 2
rt
y c c t e +
y
t
Critically damped case
(3) If a
1
2
- 4a
2
a
0
< 0, two roots are complex conjugate
1 2
cos sin
t t
y c e t c e t

+
y
t
Underdampedcase
1
2
r
i
r
t
2
1
2
1
2
( ) 3 2
2
3 3 4(2)
1 2
f x x x
r
r
+
t

Distinct real roots
2
2
2
1
2
( ) 10 25
5
10 10 4(25)
5 2
f x x x
r
r
+
t

Repeated real roots
2
3
2
1
2
( ) 17 72.5
8.5 0.5
17 17 4(72.5)
8.5 0.5 2
f x x x
r i
r i
+
+
t

Complex roots
0 2 4 6 8 10
-1
-0.5
0
0.5
1
1.5
2
2.5
3
y

=
f
(
x
)
Roots of Polynomials
x
distinct
real roots
repeated
real roots
complex
roots
MATLABs roots Function
Compute eigenvalues of companion matrix
4 3 2
5 4 3 2 1
0 c c c c c + + + + 4th-order polynomial:
2 1 3 1 4 1 5 1
/ / / /
1 0 0 0
0 1 0 0
0 0 1 0
c c c c c c c c
A

1
1
1

1
1
]
Companion
Matrix
Eigenvalue problem A
2
1
2
2
2
3
( ) 3 2 root([1 -3 2])
( ) 10 25 root([1 -10 25])
( ) 17 72.5 root([1 -17 72.5])
f x x x
f x x x
f x x x
+
+
+

Вам также может понравиться