You are on page 1of 2

Programme MATLAB 

:
clear all
close all
clc

a=1;
b=2;
eps=0.001;
f=@(x) log(x)-x.^2+2;
fplot(f,[a,b]);
grid on
[x,N]= MyDichotomieFun (f ,a ,b ,ep)
if f(a) *f(b)>0
error('intervalle indapet');
end
N=0;
while abs (b-a)/2 >eps
x= (a+b) /2;
if f(a) *f(x)>0
a=x;
elseif f(a) *f(x)<0
b=x;
else
break
end
N=N+1;
end
Figure 1

You might also like