You are on page 1of 15

Akar Persamaan (Root of equation)

b  b 2  4ac
f (x)  ax 2  bx  c  0 x1,2 
2a

1
• GRAPHICAL METHODS
Example :
Use the graphical approach to determine the mass of the bungee jumper with a drag
coefficient of 0.25 kg/m to have a velocity of 36 m/s after 4 s of free fall. Note: The
acceleration of gravity is 9.81 m/s2 and :
gm  gCd 
v(t)  tanh  t
Cd  m 

Solution :
gm  g Cd 
f (m)  tanh  t   v(t)
Cd  m 
Matlab code :
>> cd = 0.25; g = 9.81; v = 36; t = 4;
>> m = linspace(50,200);
>> fp = sqrt(g*m/cd).*tanh(sqrt(g*cd./m)*t)−v;
>> plot(m,fp),grid

2
• Incremental Search Methods
o if f(x) is real and continuous in the interval from xl to xu and f(xl) and
f(xu) have opposite signs
f (x l )f (x u )  0
there is at least one real root between xl and xu
o Incremental search methods capitalize on this observation by locating
an interval where the function changes sign
o A potential problem with an incremental search is the choice of the
increment length. If the length is too small, the search can be very time
consuming. On the other hand, if the length is too great, there is a
possibility that closely spaced roots might be missed

3
Matlab Code
function xb = incsearch(func,xmin,xmax,ns)
% incsearch: incremental search root locator
% xb = incsearch(func,xmin,xmax,ns):
% finds brackets of x that contain sign changes
% of a function on an interval
% input:
% func = name of function
% xmin, xmax = endpoints of interval
% ns = number of subintervals (default = 50)
% output:
% xb(k,1) is the lower bound of the kth sign change
% xb(k,2) is the upper bound of the kth sign change
% If no brackets found, xb = [].
if nargin < 3, error('at least 3 arguments required'), end
if nargin < 4, ns = 50; end %if ns blank set to 50
% Incremental search
x = linspace(xmin,xmax,ns);
f = func(x);
nb = 0; xb = []; %xb is null unless sign change detected
for k = 1:length(x)−1
if sign(f(k)) ~= sign(f(k+1)) %check for sign change
nb = nb + 1;
xb(nb,1) = x(k);
xb(nb,2) = x(k+1);
end
end
if isempty(xb) %display that no brackets were found
disp('no brackets found')
disp('check interval or increase ns')
else
disp('number of brackets:') %display number of brackets
disp(nb)
end 4
Problem statement :
Use the M-file incsearch to identify brackets within the interval [3, 6] for the function:

f (x)  sin(10x)  cos(3x)


Solution:
The MATLAB session using the default number of intervals (50) is :

>> incsearch(@(x) sin(10*x)+cos(3*x),3,6)


number of brackets:
5
ans =
3.2449 3.3061
3.3061 3.3673
3.7347 3.7959
4.6531 4.7143
5.6327 5.6939

5
>> incsearch(@(x) sin(10*x)+cos(3*x),3,6,100)
number of brackets:
9
ans =
3.2424 3.2727
3.3636 3.3939
3.7273 3.7576
4.2121 4.2424
4.2424 4.2727
4.6970 4.7273
5.1515 5.1818
5.1818 5.2121
5.6667 5.6970

6
BISECTION METHOD
Bisection method is a variation of the incremental search method in which
the interval is always divided in half. If a function changes sign over an
interval, the function value at the midpoint is evaluated. The location of the
root is then determined as lying within the subinterval where the sign
change occurs

Algorithm for Bisection Method : f(x)

1. Choose xl and xu as two


guesses for the root such
that f(xl) f(xu) < 0, or in
other words, f(x) changes
x
sign between xl and xu. x
xu

7
2. Estimate the root, xr of
the equation f (x) = 0 as
the mid point between xl
and xu as
x  xu
xr  
2

3. Check the followingr

a) If , then the root lies between xl and xr; then xl = xl ; xu = xr.

b) If , then the root lies between xr and xu; then xl = xr; xu = xu.
c) If then the root is xr. Stop the algorithm if this is true.

8
4. Find the new estimate of the root
x  xu
xr 
2
Find the absolute relative approximate error

x new
r  x old
r  100
a 
where
x new
r

x old
r  previous
   estimate  of  root
x new
r  current
   estimate  of  root

5. Compare the absolute relative approximate error a with the prespecified


error tolerance s.

9
Example :
Determine the mass at which a bungee jumper’s free-fall velocity exceeds 36
m/s after 4 s of free fall given a drag coefficient of 0.25 kg/m
9.81m  9.91(0.25) 
f (m)  tanh  4   36
0.25  m 
Matlab code :
Main program :

fm=@(m,cd,t,v) sqrt(9.81*m/cd)*tanh(sqrt(9.81*cd/m)*t)-v;
[mass fx ea iter]=bisect(@(m) fm(m,0.25,4,36),40,200)

10
function [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,varargin)
% bisect: root location zeroes
% [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,p1,p2,...):
% uses bisection method to find the root of func
% input:
% func = name of function
% xl, xu = lower and upper guesses
% es = desired relative error (default = 0.0001%)
% maxit = maximum allowable iterations (default = 50)
% p1,p2,... = additional parameters used by func
% output:
% root = real root
% fx = function value at root
% ea = approximate relative error (%)
% iter = number of iterations
if nargin<3,error('at least 3 input arguments required'),end
test = func(xl,varargin{:})*func(xu,varargin{:});
if test>0,error('no sign change'),end
if nargin<4|isempty(es), es=0.0001;end
if nargin<5|isempty(maxit), maxit=50;end
iter = 0; xr = xl; ea = 100;
while (1)
xmold = xr;
xr = (xl + xu)/2;
iter = iter + 1;
if xr ~= 0,ea = abs((xr - xrold)/xr) * 100;end
test = func(xl,varargin{:})*func(xr,varargin{:});
if test < 0
xu = xr;
elseif test > 0
xl = xr;
else
ea = 0;
end
if ea <= es | iter >= maxit,break,end
end
root = xr; fx = func(xr, varargin{:}); 11
FALSE POSITION METHOD
False position (also called the linear interpolation method). It is very similar to
bisection with the exception that it uses a different strategy to come up with its
new root estimate. In false position method , the location of improved estimate
of the root is intersection of staraight line joining f(xl) and f(xu) with x axis. Thus,
the shape of the function influences the new root estimate

12
Based on two similar triangles:

f (x ) f (x u )

xr  x xr  xu

f (x )  0; x r  x   0
f (x u )  0; x r  x u  0

 x r  x  f  x u    x r  x u  f  x 

x u f  x    x f  x u   x r  f  x    f  x u  

x f  x    x f  x u 
xr  u
f  x   f  x U 

13
Algorithms False-Position
1. Choose xl and xu as two guesses for the root such that f(xl) f(xu) < 0, or in
other words, f(x) changes sign between xland xu
f  x  f  x u   0

2. Estimate the root x u f  x    x f  x u 


xr 
f  x   f  x u 
3. Check the following
a. if f(xl) f(xr) < 0 , then the root between xl and xr ; then xl = xl and xu = xm
b. if f(xl) f(xr) > 0 , then the root between xr and xu ; then xl = xr and xu = xu
c. if f(xl) f(xr) = 0 , then the root is xr . Stop the algorithm is this true.
4. Find the new estimate of the root
x u f  x    x f  x u 
xr 
f  x   f  x u 
Find the absolute relative approximate error as
x new
r  x old
r  100
a 
x new
r 14
where
x old
r  previous
   estimate  of  root
x new
r  current
   estimate  of  root
5. Compare the absolute relative approximate error a with the prespecified
error tolerance s.

If a >
s , the go to step 3, else stop the algorithm.

15

You might also like