Implementation of the Bisection Method

in #programming7 years ago

Hello Steemian!!! On this occasion I will discuss about the bisection method
The initial idea of Bisection Method is the method table, where the area is divided into N parts. It's just this bisection method divides the range into two parts, of the two parts are selected which parts containing and the part that does not contain the root are removed. This is done repeatedly until retrieved the roots of the equation.
Bisection method is often referred to as a contraction of binary or method of bolzano. If on a function changed the sign at some interval, then the function values calculated at the midpoint. Then the root location is determined at the midpoint of the hose section places the occurrence of a change of sign.
The first stage of the process is to assign an arbitrary value of a and b as a function of the value of the segment limit sought. Limits a and b give the price for the function f(x) for x = a and x = b. Next step is to check if f(a) . f(b) < 0.
If the terms are met, it means that there is a root of a function in a segment of the review. If not so, must be set back the value a and b such that it fulfilled the provisions of multiplication f(a) . f(b) < 0.
With the formula m = (a + b)/a, examined whether the absolute value of f (m) < (limit deviations errors). If true, the value of x = m is the solution you're looking for. If it is not met, the new restrictions set by changing the value of b = m if f(a) . f(m) < 0, and replaced a = m if f(a) . f(m) > 0. The process of finding a new m done like the procedure that has been described.
Look at the following picture.
Given f(x) = 0; the nature of continuous and the boundaries of the interval [a, b], f(a) x f(b) ≤ 0
1.jpg

The algorithm of the Bisection Method:

  1. For n = 0, 1, 2 ... ... ... ... ... to N parts
  2. Take m = (a(n) + b(n))/2
  3. If f(a(n)) . f(m) < 0, take a(n + 1) = a(n), b(n + 1) = m
  4. If f(a(n)) . f(m) > 0, take a(n + 1) = m, b(n + 1) = b(n)
  5. If f(a(n)) . f(b(n)) = 0, then m is a root of, stop the calculation of f(x) have roots in [a(n + 1), b(n + 1)]

Bisection Method Matlab Source Code

clear;
clc;
galat = 0.001;
bawah = input('Batas Bawah  : ');
atas = input ('Batas Atas : ');
nilai = 1;
no = 0;
m0 = bawah;
clc;
fprintf('Taksiran batas bawah : %5.3f\n', bawah);
fprintf('Taksiran batas atas : %5.3f\n', atas);
fprintf('==============================================\n');
fprintf('Iterasi (bawah+atas)/2 Galat Interval \n');
fprintf('==============================================\n');
while nilai> galat
    no = no +1;
    fbawah = feval('fbi',bawah);
    m=(bawah+atas)/2;
    ftengah = feval('fbi',m);
if fbawah*ftengah==0
        disp('m adalah akarnya');
elseif fbawah*ftengah<0
        atas=m;
else
        bawah=m;
end
    nilai = abs(m0-m);
    fprintf (' %3d %8.5f %8.5f [%8.5f ; %8.5f]\n', no, m, nilai, bawah, atas);
    m0=m;
end
fprintf('==============================================\n');
fprintf('Pada Iterasi ke-%1d, Selisih Interval < %5.3f\n',no, galat);
fprintf('Jadi, akar persamaannya adalah %7.5f\n', m);

The code of the function of the fbi.m

function [y]=f(x)
y=x^3+x^2-8*x-10;

The Output Of The Bisection Method Matlab Source Code
2.jpg

Follow Me

@muzammil
https://github.com/muzammil13

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.029
BTC 62134.47
ETH 2417.18
USDT 1.00
SBD 2.54