Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Regula Falsi y Secante
Regula Falsi y Secante
FACULTAD DE INGENIERÍA
ELECTRÓNICA Y ELÉCTRICA
CURSO:
Laboratorio de Métodos Numéricos
HORARIO:
Grupo L17 Martes de 4pm a 6pm
DOCENTE:
Dr. José E. Esparta Rodriguez
ESTUDIANTES:
#MÉTODO DE LA SECANTE
clc,clear all,close all;
disp('============================================');
disp('=============METODO DE LA SECANTE===========');
disp('============================================');
##DESACTIVAR LOS MENSAJES DE ERROR
if exist('OCTAVE_VERSION')
warning('off', 'all');
end
funcion = input('Ingrese la funcion ==> ','s')
y=funcion;
funcion = inline(funcion);
xi= input("punto de incicio 1 ==> ");
xf= input("punto de inicio 2: ==> ");
erro= input("error aproximado: ==> ");
##CALCULO DEL ERROR
function ea = errora(xn,xi)
ea = abs( xn - xi );
end
##BUCLE CON LA OPERACIÓN
if funcion(xi)-funcion(xf)~=0
i=1;
fprintf ("_______________\n");
fprintf("%s\t %s\t\t %s\n", 'I', 'XN', '|EA|');
fprintf ("_______________\n");
fprintf('%.0f\t', i);
fprintf('%.5f\t\t', xi);
fprintf('%.5f\t', errora(xf,xi));
fprintf ("\n");
while errora(xf,xi)>erro
xn = xi-(((xi-xf)/(funcion(xi)-funcion(xf)))*funcion(xi));
xf = xi;
xi = xn;
i++;
fprintf('%.0f\t', i);
fprintf('%.5f\t\t', xn);
fprintf('%.5f\t', errora(xn,xf));
fprintf ("\n");
endwhile;
fprintf ("______________\n");
else
fprintf("no se puede calcular");
end
##Grafica de la función
hold on;
x=[-10:0.001:0];
fplot(y,[-10,15]);
##Cuadrar los ejes
axis([-5 8 -15 4]);
a=[-50 50];
b=a-a;
plot(a,b,'k');
plot(b,a,'k');
legend('polinomio ingresado ')
hold off;
Nota. Gráfica de la función en Geogebra
CÓDIGO EN OCTAVE