Embed presentation
Downloaded 25 times
![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) andf(b) donothave 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;](https://image.slidesharecdn.com/regulafalsi-170130044129/75/Matlab-code-for-Bisection-Method-1-2048.jpg)


This document describes a bisection method algorithm to find the root of a function f between the values a and b within a specified tolerance eps. The algorithm takes the function f, initial values a and b with opposite signs of f, maximum number of iterations N, and tolerance eps as inputs. It repeatedly bisects the interval [a,b] where f changes sign and returns the root r once the interval is smaller than the tolerance or a root is found directly at the endpoints.
![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) andf(b) donothave 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;](https://image.slidesharecdn.com/regulafalsi-170130044129/75/Matlab-code-for-Bisection-Method-1-2048.jpg)
