You are on page 1of 2

ALGORITMO PARA EL MÉTODO DE BISECCIÓN

function raiz=bisec(xizq,xder,ff)
%METODO DE BISECCION
Nmax=50; %numero maximo de interaciones
epsi=1e-5; %tolerancia de convergencia
yizq=feval(ff, xizq); yder=feval(ff, xder);
if yizq*yder<0
iter=1;
convergio=false;
while (iter<=Nmax && ~convergio)
xmed=(xizq+xder)/2; ymed=feval(ff,xmed);
convergio=abs(ymed)<=epsi | abs((xder-xizq)/2)<=epsi;
if ~convergio
if ymed*yizq>0
xizq=xmed; yizq=ymed;
else
xder=xmed; yder=ymed;
end
iter=iter+1;
end
end
if convergio
raiz=xmed;
else
raiz=NaN;
end
else
raiz=NaN;
end

>> f=inline('-x.^3/2400+x.^2/20+7*x/6+340')
f = Inline function:
f(x) = -x.^3/2400+x.^2/20+7*x/6+340
>> f=@(x)-x.^3/2400+x.^2/20+7*x/6+340
f = function_handle with value:
@(x)-x.^3/2400+x.^2/20+7*x/6+340
>> raiz=bisec(100,200,f)
raiz =
166.3293
>> f=inline('21*x.^3/5000000-127*x.^2/1000000+1293*x/50000')
f =Inline function:
f(x) = 21*x.^3/5000000-127*x.^2/1000000+1293*x/50000
>> f=@(x)21*x.^3/5000000-127*x.^2/1000000+1293*x/50000
f = function_handle with value:
@(x)21*x.^3/5000000-127*x.^2/1000000+1293*x/50000
>> raiz=bisec(-5,3,f)
raiz =
0

You might also like