Analysis Bisection and Golden-Section Method in Matlab: 1. Preliminary

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

ANALYSIS BISECTION AND GOLDEN-SECTION METHOD IN

MATLAB
1
Maizan Rin Dalwain
1
Departemen Tenik Geofisika, Fakultas Teknik Sipil Lingkungan dan Kebumian
Institut Teknologi Sepuluh Nopember (ITS)

ABSTRACT
Bisection method is root-finding method that applies to any continuous function
for which one knows two values with opposites signs. Golden-section method is method
which is searching for minimum of the function on given interval <a,b>. In this
experiment we we solve mathematical problems on MATLAB using bisection method and
golden-section method. We find for roots numerically and to determine the maximum of
function in one example of a mathematical calculation on MATLAB.
Keywords : Bisection Method, Golden Section, Iteration

1. PRELIMINARY Similar to bisection, the basic idea of


The bisection method is a closed this method is to use the old value as a new
method to determine the root solution of value, iteratively. As a result, the range /
non-linear equations. The initial idea of the initial interval of the selected variable will
bisection method is the table method where be narrower, because there are some
the area is divided into N parts. While the variable sub-intervals that are eliminated,
bisection method divides the range into 2 until the desired convergence level is
(two) parts only. The roots of the nonlinear obtained. In mathematics, iterations can be
equation are sought through an iterative interpreted as a process or method that is
process, with the main principle as follows: used repeatedly (repetition) in solving a
choosing the part containing the root and mathematical problem.
discarding the non-rooted ones until the 2. METODOLOGY
root equation is obtained.
2.1 Tools
Golden section is one method or
The tool that will be used in this
numerical optimization method that can be
experimental calculation is MATLAB
applied to functions that are unimodal. Both computing application software.
types of optimization, namely
maximization and minimization can be 2.2 Flow Chart
solved in this way. The Golden-section Steps to perform calculations using
(search) method is a simple one-variable Bisection method and golden-section
optimization method, and has an approach method through the MATLAB software
similar to the bisection method in will be described in the following flow
determining the root of nonlinear equations. chart.
(x) is continuous between a and b) now we
see that c is midway between a and b, which
is c = 1/2 (a + b ), and produce f (c) which
is equal to 8.32 x 10-5 and the graph is
marked with an asterisk. The graph shown
is as follows.

Fig 1. Bisection Method Flow Chart Fig 1. Graphic coparison between


xmin-xmax and f(x)= x3- x - 6 = 0
Likewise, if f (x) = x2.5 - x - 6 = 0 with
the values a (xmin) = -50 and b (xmax) =
50. Produce f (c) which is equal to 0. In
this equation, there is an imaginary parts
which are indicated when the value of a <0.
If the value of a is replaced by 0, the
imaginary value is null. And the warning
does not appear on Matlab because there
are imaginary parts. So the graph shown is
as follows.

Fig 2. Golden Section Method Flow Chart

3. RESULT AND ANALYSIS


The interval method for two or also
called the middle interval method is one
method that is often used to find a root. Fig 2. Graphic coparison between
Suppose we know that f (x) = x3- x - 6 = 0 xmin-xmax and f(x)= x2.5 - x - 6 = 0
has one root between xmin = a = -10 and If f (c) has the same sign as f (a), then
xmax = b = 10; then f (a) and f (b) have the root lies between c and b; or other
opposite signs (assuming that the graph f possibilities the roots lie between a and c.
Then the interval in determining the root is From the analysis using both methods
reduced to half the width of the original it can be concluded that:
range. We repeat the process, reducing the
 In the first equation using bisection, the
interval to 1/4, 1/8, 1/16, until we can
effect of the value of xmin, xmax and
determine the root according to the
accuracy we want. the iteration is very small because it is
not visible through the graphic
Basically, the golden-section method is  In the second equation using bisection,
almost similar to the bisection method in the effect of the value of xmin, xmax,
determining nonlinear roots. Similar to and iterations affects the root value in
bisection, the basic idea of this method is to the form of an imaginary value.
use the old value as a new value, iteratively.  In the Golden section, the effect of the
As a result, the range / initial interval of the value of xmin, xmax and iterations is
chosen variable will increasingly narrow, very large.
because there are some variable sub-
intervals that are eliminated, until the BIBLIOGRAPHY
desired convergence level is obtained. 1. https://diyarkholisoh.files.wordpress.c
In the golden-section equations are om/2008/12/optimasi-numerik-doc-
dy.pdf
used If xl = 0 and x2 = 4.
Let's assume a as x1 and b as x2. The error
value given is 0,0001. The value is used for
the lower limit of the beginning, while b is
used for the upper limit. The error value
itself is used to estimate the error value to
be smaller. The maximum iteration value is
used to determine the value obtained. In fig.
3 there is a graph can be seen that there is
an asterisk outside the graph line. This is
because the value of b does not include the
maximum value so that the star symbol
intersects the line in the graph.

Fig 3. Graphic Golden-Section


4. CONCLUSION
Appendix
1. Bisection (x3-x-6 = 0)
Script sebagai berikut
%MAIZAN RIN DALWAIN error = abs(f(xr));
%03411740000022 %abs = nilai absolute
%KOMGE D if(error<=error_max ||
clear all iter>=iter_max) %|| or kalo | and,
clc merupakan sebuah kondisi
break;
f = @(x) x.^3-x-6; end
xmin = -50
xmax = 50; if(f(xr))*(f(x1))>0
error_max = 0.0001; x1 = xr;
%perkiraan besar error dalam else(f(xr))*(f(xu))<0;
perhitungan, diharapkan sekecil xu = xr;
mungkin end
iter_max = 100; end
%pengulangan perhitungan
data = xmin:xmax; disp('Root=')
disp(xr)
x1 = xmin; %pengganti nama
agar fungsi pada while tidak plot(data,f(data))
panjang hold on
xu = xmax; plot(xr,f(xr),'*')
iter = 0;
error = 1; %syarat bisection (secara
while(1) matematis)
%untuk looping %x1 = xr, jika (f(xr))*(f(x1))>0
iter = iter+1; %xu = xr, jika (f(xr))*(f(xu))<0
%iter xr error = syaratnya %syarat lain : error<=error_max
xr = (x1+xu)/2; atau iter>=iter_max
%mencari nilai tengah dr nilai min
dan max

2. Bisection (x2.5-x-6 = 0)
Script sebagai berikut
%MAIZAN RIN DALWAIN iter = 0;
%03411740000022 error = 1;
%KOMGE D while(1)
clear all %untuk looping
clc iter = iter+1;
%iter xr error = syaratnya
f = @(x) x.^2.5-x-6; xr = (x1+xu)/2;
xmin = -50 %mencari nilai tengah dr nilai min dan
xmax = 50; max
error_max = 0.0001; %perkiraan error = abs(f(xr));
besar error dalam perhitungan, %abs = nilai absolute
diharapkan sekecil mungkin if(error<=error_max ||
iter_max = 100; %pengulangan iter>=iter_max) %|| or kalo | and,
perhitungan merupakan sebuah kondisi
data = xmin:xmax; break;
end
x1 = xmin; %pengganti nama
agar fungsi pada while tidak panjang if(f(xr))*(f(x1))>0
xu = xmax; x1 = xr;
else(f(xr))*(f(xu))<0;
xu = xr; hold on
end plot(xr,f(xr),'*')
end
%syarat bisection (secara matematis)
disp('Root=') %x1 = xr, jika (f(xr))*(f(x1))>0
disp(xr) %xu = xr, jika (f(xr))*(f(xu))<0
%syarat lain : error<=error_max atau
plot(data,f(data)) iter>=iter_max
3. Golden-Section
%MAIZAN RIN DALWAIN x2=x2-d
%03411740000022 iter=iter+1;
%KOMGE D
if k(xl)>k(x2)
clear all x1=xl;
clc else k(xl)<k(x2)
x2=x2;
k=@(x) 2*sin(x)-0.1*x.^2; end
xmin=0; x_lama = xl;
xmax=4; err = abs(x1-x_lama);
error_max=0.0001; if (error<=error_max ||
iter_max=100; iter>=iter_max)
data = xmin:xmax break;
end
x1=xmin; end
x2=xmax;
iter=0; disp('Root=')
error=1; xr=(x1+x2)/2

while(1) plot(data,k(data));
d= (1.6180339886-1)*(x2-x1); hold on
xl=x1+d plot(xr,k(xr),'*g')

You might also like