Matlab code for Bisection Method

Taimoor_Gondal 2,617 views 2 slides Jan 30, 2017
Slide 1
Slide 1 of 2
Slide 1
1
Slide 2
2

About This Presentation

numeric analysis Bisection method. MATLAB provides tools to solve math. Using linear programing techniques we can easily solve system of equations. This file provides a running code of Bisection Method


Slide Content

bisetion:

function [r] = ncasinmt(f,a,b,N,eps)
f = inline('x^3-9*x+1')
a=2;
b=4;
N=18;
eps=0.0001;
if(f(a)==0)
r=a;
return;
elseif(f(b)==0)
r=b;
return;
elseif(f(a)*f(b)>0)
error('f(a) and f(b) donot have opposite sign')
end
for i = 2:N
c=(a+b)/2;
if(f(c)==0)
r=c;
return;
elseif(f(a)*f(c)<0)
b=c;
else a=c;

end
if (b-a)/2<eps;
if(abs(f(a))<abs(f(b))&&abs(f(a))<eps)
r=a;
return;
elseif(abs(f(b))<eps)
r=b;
return;
end
end
end
end