You are on page 1of 1

xi = input('Limite inferior: ');

xs = input('Limite superior: ');


n = input('Numero de iteraciones: ');
fxi = (exp(1) ^ (xi * -1)) - xi;
fxs = (exp(1) ^ (xs * -1)) - xs;
fcom = fxi * fxs;
if fcom < 0
xr = (xi + xs) / 2;
fxr = (exp(1) ^ (xr * -1)) - xr;
fprintf('xi = %f xs = %f xr = %f \n',xi,xs,xr);
fcom = fxi * fxr;
if fcom > 0
xi = xr;
else
if fcom < 0
xs = xr;
else
raiz = xr;
end
end
fprintf('xi = %f xs = %f xr = %f',xi,xs,xr);
c = 2;
while c <= n
xrant = xr;
xr = (xi + xs) / 2;
ea = ((xr - xrant) / xr) * 100;
if ea < 0
ea = abs(ea);
end
c = c + 1;
fxi = (exp(1) ^ (xi * -1)) - xi;
fxs = (exp(1) ^ (xs * -1)) - xs;
fxr = (exp(1) ^ (xr * -1)) - xr;
fcom = fxi * fxr;
if fcom > 0
xi = xr;
else
if fcom < 0
xs = xr;
else
raiz = xr;
end
end
fprintf('\n c = %f xi = %f xs = %f xr = %f fxi = %f fxs = %f fxr = %f er
ror = %f',c,xi,xs,xr,fxi,fxs,fxr,ea);
end
else
disp('El metodo no aplica...');
end

You might also like