You are on page 1of 2

UNIVERSIDAD AUTONOMA DE COAHUILA

FACULTAD DE SISTEMAS

Materia: Mtodos Numricos


Tema: Programa Biseccin y Regla Falsa en
Matlab
Profesor: Irma Delia Garca Calvillo
Alumno: Carlos Ivn Monsivis Bravo

Arteaga Coahuila Mxico a 9 de Octubre del 2015

Codigo Biseccion
clc;
f=@(x) exp(x)-2-x;
a=1;
b=1.8;
for i=1:100
c=(a+b)/2;
if f(c)>0
b=c;
else a=c;
end
end
a=1; b=2; p=c;
for i=1:100
c=(a+b)/2;
er(i)=f(c)-f(p);
if f(c)>0
b=c;
else a=c;
end
end
fprintf('Root of given
equation is %f',c)
plot(er);
title('Plot of error')
xlabel('Number of
iterations')
ylabel('Error')
grid on;

Resultado:
Root of given equation is
1.146193

Codigo Regla Falsa


clc;
f=@(x) exp(x)-2-x;
a=2; b=3;
for i=1:10
x0=a; x1=b;
fprintf('\n Hence root
lies between (%.4f,
%.0f)',a,b)
x2(i)=x0-(x1-x0)/
(f(x1)-f(x0))*f(x0);
if f(x2(i))>0
b=x2(i);
else a=x2(i);
end
fprintf('\n Therefore,
x2=%.4f \n Here, f(x2)=
%.4f',x2(i),f(x2(i)))
p=x2(i);
end
for i=1:10
error(i)=p-x2(i);
end
Answer=p
plot (error)
grid on;
title('Plot of error');
xlabel('iterations');
ylabel('Error');

Resultado:
Answer: 1.1466

You might also like