Bisection method for finding roots - Matlab Program

Matlab can be used to find roots of functions. One method is bisection method. We design a matlab code to find approximate roots of functions using theories of bisection method which is a section of numerical methods.

Download Matlab Code

% final answer accuracy is enough for
%variable introduction
% X1 is the left point
% X2 is the right point
% X3 is the average value, otherwise X3=(X1+X2)/2
% value takes the value of function when X3 substitute it in the function
% previousX1Value takes the value of function when X1 substitute it in the function
% nextX2Value takes the value of function when X2 substitute it in the function

Matlab Code

format long;
syms x;
sym value;

f(x) = x^2 -4*x -13;
X1 = -2.2;
X2 = -2.1;
n=1;

while n<50
X3 = (X1 + X2)/2;
value = f(X3);
previousX1Value = f(X1);
nextX2Value = f(X2);

if ( value * previousX1Value )<0
X2 = X3;

else
X1 = X3

end

if value <0
value = -1*value;
end

if value<0.000000000001
disp(double(X3));
end

n=n+1;

end
clear all;




browse topics