MATLAB Code For Bisection Method
MATLAB Code For Bisection Method
MATLAB Code For Bisection Method
% Bisection method
clear all, close all, clc
format short
f = @(x) x.^3+4*x.^2-10;
a=1; b=2;
max_I=20;% maximum number of iterations
tol=10^(-5);
fa=feval(f,a); % Initial guess
fb=feval(f,b);
if fa*fb>0,
disp('Wrong choice')
end
for k=1:max_I
c=(a+b)/2;
C(k)=c;
fc=feval(f,c);
Fc(k)=fc;
if fc==0,break
end
if fb*fc>0;
b=c;
fb=fc;
else
a=c;
fa=fc;
end
if abs(fc)<tol,break
end
end