Académique Documents
Professionnel Documents
Culture Documents
Method
ds for use in
n Root Disccovery
Dan Cookk
Abstract:
Introduction:
Physical Analysis:
Take the ffollowing diaggram as an exxample:
When the switch is closed at time t=0, resulting in the removal of the battery, the circuit will experience
a transient response. During this period the current flowing in the circuit will decrease exponentially
with time according to the following equation:
2
/ 2
+ / +( / =0
Where “L” is the inductor value, “R” is the resistor value, and “C” is the capacitor value
For the given problem we want to implement a circuit whose transient response allows the charge in the
circuit to dissipate to 1 percent of its initial value in a time of .05 seconds. Given are the values of “L”
and “C”, so only the resistor value “R” needs to be solved for. The “R” function is given as:
( )= − (2 )
cos(1/ −( /2 )2 )− / 0
To find the correct resistor value the root of this equation must be solved for. The bisection, modified
false positive, fixed point iteration, Newton‐Raphson, and secant methods will be used to find this value.
Numerical Analysis
Bracket Methods
The first two methods described here are known collectively as bracketing methods. These methods are
based on the fact that in the local area of a root the function will change signs on the left and right of
the root.
Bisection Method
The first root finding method that will be discussed is the bisection method. With this method two
guesses are entered such that the root is between them (i.e. the function is positive for one value and
negative for the other value). It then takes the midpoint of these values as an approximate root. If the
signs of the midpoint and upper guess are of the same sign then it is known that the root lies in the
lower subinterval. If the signs are different then it is know that the root lies in the upper subinterval and
a new midpoint between the upper guess and the old midpoint is taken and the process repeats until
the root is found. This can be shown as [1]:
2
When f(xl)f(xr)<0 the root is in the lower interval; set xu=xr
When f(xl)f(xr)>0 the root is in the upper interval; set xl=xr
When f(xl)f(xr)=0 the root is xr
Figure 1: Bissection Method
d. www.leda‐tuttorial.org
False Posiition Method
The false position metthod relies on
n the magnitu udes of the u pper and low wer guesses to find a root. This
method constructs
c a line between a f(xlower)) and where this line cro
n f(xupper) and ossed the x‐aaxis is
where thee approximate root will be e. This interse
ection of the xx‐axis can be found using [[1]:
This approximation off the root, Xroot, then rep places the guuess that has the same siggn as Xroot. Thus
one end oof the line will always be ffixed on one of the guess es and the other end poin nt will move along
the functiion until its in
ntercept is eq oot will alwayys be contained be
qual to the root. This is usseful as the ro
the upperr and lower guess [1]. This process conttinues until a root is found d.
Figure 2: False Position Me
ethod. www.wikkipedia.org
Open Methods
The next three root finding
f metho ods used are
e known as oopen method ds. These meethods depennd on
equationss, and typicallly only requirre one guess iin comparisonn to the bracketing metho ods which req quired
two guessses that contaain the root [1].
Fixed‐Poinnt Iteration M
Method
This meth hod is based oon changing the equation ff(x)=0 to:
When a vvalue of x is foound such thaat x=g(x), it iss equivalent tto finding a so
olution to thee original equ
uation
f(x)=0. This method finnds a new valu ue of x based on the old vaalues of x. Thhis is seen as [[1]:
ntinued until g(xi)=x, mean
This is con ning there is aa root at the xx value used in the functio
on.
Figure 3: Fixxed Point Metho
od. www.pathfinder.scar.utoro
onto.ca
′
ess of finding the tangent lline interceptt is continuedd until the tan
The proce ngent line inteercepts the ro
oot.
Figure 4: Ne
ewton‐Raphson Method. www..gilkalai.wordprress.com
Secant Meethod
The secannt method is very similar to the Newtton‐Raphson method in itts approach. Both use tangent
lines and their x‐intercept to apprroximate the root. The m ain differencce is that thee Newton‐Rap
phson
uses the ffunctions derivative to con nstruct the taangent line, w
while the secaant method uses a differen nce to
compute a tangent line e. This methood uses the fo ormula [1]:
ess from this point onward
The proce d is the same as the Newtoon‐Raphson m
method
Figure 5: Se
ecant Method. w
www.jwilson.coe
e.uga.edu
Results
Secondly, the resistor function is plotted to give a general idea of the shape and the root of the
equation. The equation was this:
( )= − (2 )
cos(1/ −( /2 )2 )− / 0
The plot done in matlab is as follows:
0.06
0.05
0.04
0.03
0.02
0.01
-0.01
-0.02
-0.03
500 550 600 650 700 750 800 850 900 950 1000
Figure 6: Plot of the Resistor function
From this plot it can be seen that the root is in the range of 550<R<650.
Bisection Method
From the techniques described above in the Numerical Methods portion, the root to this equation can
be solved for. Bisection is the first method used. The code used to determine the root is based off this
pseudo‐code [2]:
'Bisection Method
'Start loop
Do While (abs(right - left) > 2*epsilon)
'Find f(midpoint)
If ((f(left) * f(midpoint)) < 0) Then
'Throw away right half
right = midpoint
ElseIf ((f(right) * f(midpoint)) < 0)
'Throw away left half
left = midpoint
Else
'Our midpoint is exactly on the root
Exit Do
End If
Loop
Return midpoint
The resulting root is R=605.8899 after 14 iterations of the code.
False Position Method
The pseudo‐code used for this method is as follows [3]:
while(iteration <=max)
compute f(a)
compute f(b)
x = a - ((f(a)*(b-a)) / (f(b)-f(a))
increment iteration
Test:
if |x-xold| < epsilon*|x| then
output x
goto stop
else
output (iteration, a, b, x)
xold = x
compute f(x)
stop
The root according to this method, after 14 iterations is R=605.8841
Fixed‐Point Iteration
The pseudo‐code used for this method is as follows [4]:
WHILE RelErr
R >= Tol and K <= Max
x DO
K := K+1 {Incremen
nt the
e coun
nter}
Pold := Pterm {Previous iter
rate }
Pterm := Pnew {Curren
nt ite
erate }
Pnew := g(P
Pterm) {C
Compute new it
terate }
Dg := Pnew
w - Pterm {Dif
fference in g
g(x)}
Delta := |D
Dg| {
{Absolute er
rror}
RelErr =
:= 2*Delta/(|
2 ll)
Pnew|+Smal (
(Relative Er
rror}
Dx :=
: Pterm - Pold {D
Difference
e in x}
Slope :=
= Dg/Dx {g'(Pk)}
}
The resultting root is givven as 605.72
264 with 14 itterations.
Newton‐R
Raphson Meth
hod
The pseud
do‐code used
d for this meth
hod is as follo
ows [5]:
es=eo
xr=x0 % initiali
ize the roo
ot with so
ome value x
x0
iter =0 % initiali
ize the ite
eration co
ounter
ea=999 % initiali
ize the rel
lative err
ror
% Begin iteration
n loop
while ea<es
e % test to see i if relativ
ve error is less then
stoppi
ing criteri
ia
xrol
ld = xr % update old value of root
xr=x
xrold-f(xr
rold)/f'(xr
rold) % calcul
late new r
root
iter
r=iter+1 % update
e the itera
ation coun
nter
if xr
x ~= 0 e absolute relative error
% update
ea=abs((x
xr-xrold)/x
xr)*100 % calculat
te relativ
ve error
end
end
root=xr % fina
al error
The root iis found to be
e R=605.8841
1 after 14 iterations
Secant Method
The pseudo‐code is as follows [6]:
This gives a root of R=605.8841 after 14 iterations of the code
Summary of results (all after 14 iterations of the code):
Method Bisection False Position Fixed‐Point Newton Secant
Root Value 605.8899 605.8841 605.7264 605.8841 605.8841
This table demonstrates that, after fourteen iterations, the false position, newton‐raphson, and secant
root methods all yield results that are equivalent to four decimal places. For a fixed number of
iterations the newton‐raphson method is generally considered the most accurate method [1]. It is also
worth noting the difference between the methods to help further analyze the results.
From comparing the previous two tables it can be determined that for a relatively simple equation with
a derivative that can be taken and that has only one root, the false position is the best bracketing
method, and the newton‐raphson method is the best open method. While the secant and newton
methods gave the same result, for a more complex function the newton method will most likely find the
root more quickly than the secant method.
Conclusion
When comparing the various methods available to find the root of a function, there is no definite
method that stands out above the rest. For most general equations it seems that the newton method
would be the prefered option in that it converges the quickest and only one guess has to be made that
can be above or below the root. However if the functions derivative is taxing to find, this method may
not be the best, and the secant method may work better. The bracketing methods hold one significant
advantage in that they always converge on the root. As long as the two guesses bracket the root, the
root can and will be found with these methods. However this is also the disadvantage with bracketing
methods. If a graphing utility is not available it may be difficult to pick a range where the root falls
making the bracketing methods useless. While a computer can run all of these programs efficiently, it
requires a knowledgeable person to understand which of these methods best fits the requirements of
the problem.
References
[1] Chapra, Steven. Numerical Methods for Engineers. Pg 130‐150. 2010
[2] Wikipedia. Bisection Method. 2010
[3] www.physics.arizona.edu. False‐Position Method. 2010
[4] www.physics.arizona.edu. Fixed‐Point Method. 2010
[5] www.cs.purdue.edu. Newton‐Raphson Method. 2010
[6] www.vortex.bd.psu.edu. The Secant Method. 2010
[7] Wikipedia. Numerical Analysis. 2010
Appendix‐Matlab Code
Function code
function y = fcn(x)
y = exp(-x.*(.05)./(2.*5)).*(cos(sqrt((1./(5.*10.^-4))-
((x./(2.*5)).^2).*.05)))-.01;
Function and Derivative code (for use with Newton Method)
function [y, deriv] = fcn_nr(x)
y = exp(-x.*(.05)./(2.*5)).*(cos(sqrt((1./(5.*10.^-4))-
((x./(2.*5)).^2).*.05)))-.01;
deriv=exp(-0.005.*x)*((-0.005*cos(sqrt(2000 - 0.0005.*x.^2)) +
(0.0005.*x.*sin(sqrt(2000 - 0.0005*x.^2)))/sqrt(2000 - 0.0005* x.^2)))
Bisection Code
function y = bisection ( f, a, b, TOL )
sfa = sign(feval(f,a));
Nmax = floor ( log((b‐a)/TOL) / log(2.0) ) + 1
for i = 1 : Nmax
p = ( a + b ) / 2.0;
sfp = sign(feval(f,p));
if ( (b‐a)<2*TOL )
if ( nargout == 1 )
y = b‐a
end
return
elseif ( sfa * sfp < 0 )
b = p;
else
a = p;
sfa = sfp;
end
end
False Position Code
function y=falsepos (f,a,b,error, maxit)
xl = a
xu = b
maxerror=error
count = 0;
rel_error = 1;
xr = xu;
xr = xu - (fcn(xu)*(xu-xl)/(fcn(xu)-fcn(xl)));
if xr ~= 0
rel_error = abs((xr - xrold)/xr) * 100;
end
test = fcn(xl) * fcn(xr);
if test == 0
rel_error = 0;
elseif test < 0
xu = xr;
else
xl = xr;
end
end
xr
Fixed Point Code
function y=op(maxerror, guess, it)
count = 0;
error = 1;
maxit=it
x=guess
while (error > maxerror) & (count < maxit)
count = count + 1
xnew=feval('fcn',x)
error = abs((xnew - x)/xnew) * 100
x=xnew
end
Newton‐Raphson Code
function y=newrap(itermax, errmax, guess)
x = guess;
iter = 0;
error = 1;
iter = iter + 1;
[f fprime] = fcn_nr(x);
xnew = x - f / fprime;
error = abs((xnew - x)/xnew) * 100;
x = xnew;
end
Secant Code
iter = 0;
error = 1;
iter = iter + 1;
f1 = fcn(x1);
f2 = fcn(x2);
x1 = x2;
x2 = x3;
end
x3