tarea biseccion y regla falsa carlos ivan monsivais bravo
DESCRIPTION
Programas en Matlab de Bisección y Regla FalsaTRANSCRIPT
UNIVERSIDAD AUTONOMA DE COAHUILA
FACULTAD DE SISTEMAS
Materia: Métodos Numéricos
Tema: Programa Bisección y Regla Falsa en Matlab
Profesor: Irma Delia García Calvillo
Alumno: Carlos Iván Monsiváis Bravo
Arteaga Coahuila México a 9 de Octubre del 2015
Codigo Biseccion Codigo Regla Falsaclc;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
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);endfor i=1:10 error(i)=p-x2(i);endAnswer=pplot (error)grid on;title('Plot of error');xlabel('iterations');ylabel('Error');
Resultado:
Answer: 1.1466