Embed presentation
Download to read offline
![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
-----------------------------
Taimoor Gondal,
COMSATS Wah Cantt
end](https://image.slidesharecdn.com/bisectionmethode-180219134742/75/Bisection-methode-alternate-1-2048.jpg)

The document outlines a MATLAB function called 'ncasinmt' for finding the root of a cubic function using the bisection method. It checks if the function values at the boundaries are equal to zero, verifies that they have opposite signs, and iterates to find the root within a specified tolerance. The function parameters include the function itself, boundaries, number of iterations, and the desired precision.
![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
-----------------------------
Taimoor Gondal,
COMSATS Wah Cantt
end](https://image.slidesharecdn.com/bisectionmethode-180219134742/75/Bisection-methode-alternate-1-2048.jpg)