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

Xavier University - Ateneo de Cagayan University

College of Engineering
Electronics Engineering Department

MACHINE PROBLEM #2
BISECTION AND SECANT METHOD

Submitted by:

Instructor:

ROMMEL PEDRAZA

ENGR. MARY JEAN O. APOR, PECE, MEng

BSEcE 5

Title and Objective

(05):____

Procedure, Data, Results

(20):____

Observation, Analysis

(30):____

Conclusion

(25):____

Tardiness

(10):____

Presentation, Neatness

(20):____

Total

(100):____

INTRODUCTION
Bisection Method
The Bisection Method is a numerical method for estimating the roots of a polynomial f(x). It is one of
the simplest and most reliable but it is not the fastest method. Assume that f(x) is continuous.
Algorithm for the Bisection Method: Given a continuous function f(x)
1. Find points a and b such that a < b and f(a) * f(b) < 0.
2. Take the interval [a, b] and find its midpoint x1.
3. If f(x1) = 0 then x1 is an exact root, else if f(x1) * f(b) < 0 then let a = x1, else if f(a) * f(x1) < 0 then
let b = x1.
4. Repeat steps 2 & 3 until f(xi) = 0 or |f(xi)| <= DOA, where DOA stands for degree of accuracy.

For the ith iteration, where i = 1, 2, . . . , n, the interval width is


xi = 0.5
xi1 = ( 0.5 )i ( b a )
and the new midpoint is xi = ai1 +

xi

Secant Method
The Newton-Raphson method of solving a nonlinear equation f (x)

0 is given by the iterative formula

(first equation)

One of the drawbacks of the Newton-Raphson method is that you have to evaluate the derivative of the
function. With availability of symbolic manipulators such as Maple, MathCAD, MATHEMATICA and

MATLAB, this process has become more convenient. However, it still can be a laborious process, and
even intractable if the function is derived as part of a numerical scheme. To overcome these drawbacks,
the derivative of the function, f (x) is approximated as second equation and third equation:

The above equation is called the secant method. This method now requires two initial guesses, but
unlike the bisection method, the two initial guesses do not need to bracket the root of the equation. The
secant method is an open method and may or may not converge. However, when secant method
converges, it will typically converge faster than the bisection method. However, since the derivative is
approximated as given by Equation (2), it typically converges slower than the Newton-Raphson method.
The secant method can also be derived from geometry, as shown in Figure 1. Taking two initial guesses,
i 1 x and i x , one draws a straight line between ( ) i f x and ( ) i 1 f x passing through the x -axis at i 1 x .
ABE and DCE are similar triangles.
Hence

OBJECTIVES
Test Bisection and Secant method with initial guesses
Use stopping criterion 0.0000001
Based the method on bungee jumping problem

MATLAB CODES

function y = f(x) %declaration of function y


%constant values
g = 9.81;
cd = 1.2;
m = 55;
k = cd/m;
v = 20;
%bunjee jump formula
y = (sqrt (g/k))*tanh(sqrt(g*k)*x) -v;
%Bisection method
clc;
clear all;
Ea = 100; %starting Ea
Es = 0.0000001; %Stopping criterion
xl = 0; %1st guess
xu = 1; %2nd guess
xrold = 0;
iter =0;
while (Ea > Es);
iter = iter +1;
fl=f(xl);
xr = (xl+xu)/2; %bisection formula
fr = f(xr);
Ea = abs((xr-xrold)/xr) *100; %computation
for approximate error
check = fl*fr;
display(['ITERATION ',num2str(iter)]);
display([' xr = ',num2str(xr)]);
display([' check = ',num2str(check)]);
display([' Ea = ',num2str(Ea)]);
%cases
if (check > 0);
xl = xr;
xrold=xr;
elseif (check < 0);

xu = xr;
xrold = xr;
else
break;
end
end
display('_______________________');
display(['ROOT = ',num2str(xr)]);
%Secant method
clc;
clear all;
format long;
Ea = 100;
Es = 0.0000001; %stopping criterion
x0 = 1;% guess 1
x1 = 2;%guess 2
xrold = 0;
iter =0;
while (Ea > Es);
iter = iter +1;
fx0=f(x0);
fx1=f(x1);
xr = x1-(fx1*(x0-x1))/(fx0-fx1);%secant
method formula
Ea = abs((xr-xrold)/xr) *100; %approximate
percent error
display(['ITERATION ',num2str(iter)]);
display([' xr = ',num2str(xr)]);
display([' Ea = ',num2str(Ea)]);
x0 = x1;
x1 = xr;
xrold = xr;
end
display('_______________________');
display(['ROOT = ',num2str(xr)]);

OUTPUT
Bisection Method
iteration 1
X(root) = 3
check = 171.5492
approximate error = 100
iteration 2
X(root) = 4
check = 377.7592
approximate error = 25
iteration 3
X(root) = 4.5
check = 414.848
approximate error = 11.1111
iteration 4
X(root) = 4.75
check = 425.2328
approximate error = 5.2632
iteration 5
X(root) = 4.875
check = 429.1282
approximate error = 2.5641
iteration 6
X(root) = 4.9375
check = 430.8183
approximate error = 1.2658
iteration 7
X(root) = 4.9688
check = 431.6059
approximate error = 0.62893
iteration 8
X(root) = 4.9844
check = 431.9861
approximate error = 0.31348
iteration 9
X(root) = 4.9922
check = 432.173
approximate error = 0.15649
iteration 10
X(root) = 4.9961
check = 432.2656
approximate error = 0.078186
iteration 11
X(root) = 4.998
check = 432.3117
approximate error = 0.039078
iteration 12

X(root) = 4.999
check = 432.3347
approximate error = 0.019535
iteration 13
X(root) = 4.9995
check = 432.3462
approximate error = 0.0097666
iteration 14
X(root) = 4.9998
check = 432.3519
approximate error = 0.0048831
iteration 15
X(root) = 4.9999
check = 432.3548
approximate error = 0.0024415
iteration 16
X(root) = 4.9999
check = 432.3562
approximate error = 0.0012207
iteration 17
X(root) = 5
check = 432.3569
approximate error = 0.00061036
iteration 18
X(root) = 5
check = 432.3573
approximate error = 0.00030518
iteration 19
X(root) = 5
check = 432.3575
approximate error = 0.00015259
iteration 20
X(root) = 5
check = 432.3576
approximate error = 7.6294e-05
iteration 21
X(root) = 5
check = 432.3576
approximate error = 3.8147e-05
iteration 22
X(root) = 5
check = 432.3576
approximate error = 1.9073e-05
iteration 23
X(root) = 5

check = 432.3576
approximate error = 9.5367e-06
iteration 24
X(root) = 5
check = 432.3576
approximate error = 4.7684e-06
iteration 25
X(root) = 5
check = 432.3576
approximate error = 2.3842e-06
iteration 26
X(root) = 5
check = 432.3577
approximate error = 1.1921e-06
iteration 27
X(root) = 5

check = 432.3577
approximate error = 5.9605e-07
iteration 28
X(root) = 5
check = 432.3577
approximate error = 2.9802e-07
iteration 29
X(root) = 5
check = 432.3577
approximate error = 1.4901e-07
iteration 30
X(root) = 5
check = 432.3577
approximate error = 7.4506e-08
-----------------------------------------------------------EXACT ROOT = 5

Secant Method
ITERATION 1
xr = -6.6636
Ea = 100
ITERATION 2
xr = -0.78694
Ea = 746.769
ITERATION 3
xr = 2.3811
Ea = 133.0501
ITERATION 4
xr = 0.17403
Ea = 1268.1843
ITERATION 5
xr = -0.07199
Ea = 341.7432
ITERATION 6

xr = 9.1081e-05
Ea = 79139.271
ITERATION 7
xr = -3.3632e-08
Ea = 270915.8192
ITERATION 8
xr = 1.9898e-17
Ea = 169020010123.739
ITERATION 9
xr = 0
Ea = Inf
ITERATION 10
xr = 0
Ea = NaN
_______________________
ROOT = 0

ANALYSIS AND CONCLUSION

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