Está en la página 1de 9

“Año del Fortalecimiento de la Soberanía Nacional”

UNIVERSIDAD NACIONAL MAYOR DE SAN MARCOS


(Universidad del Perú, Decana de América)

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

Método de la secante y Metodo de la Regula Falsa

ESTUDIANTES:

Arias Quispe Diego Jordan 21190238

Asencios Huerta, Christian Luis 21190205

Auqui Torres Luis Enrique 21190260

Aylas Paucar Vladimir Sthebin 21190117

Barreno Bustamante Cesar Manuel 21190015

Chang Herrera Miguel Angel 21190201

Ciudad Universitaria, 7 de noviembre de 2022


CÓDIGO EN OCTAVE

#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

clc,clear all,close all;


disp('================================================');
disp('=============METODO DE LA REGLA FALSA===========');
disp('================================================');
##DESACTIVAR LOS MENSAJES DE ERROR
if exist('OCTAVE_VERSION')
warning('off', 'all');
end
funcion = input('Escriba la f(x) entre parentesis ==> ','s')
y=funcion;
funcion = inline(funcion);
xi = input('Ingrese el valor de xi inferior ==> ');
xu = input('Ingrese el valor de xu superior ==> ');
cantidad = input('Ingrese el numero de iteraciones ==> ');
##CALCULO DEL ERROR
function ea = errora(xi,xr)
ea = abs(xr - xi);
end
i=1;
if funcion(xi)*funcion(xu)<0
fprintf("%s\t%s\t%s\t%s\t%s\t\n", 'i','xi','xu','xr','|EA|')
while i < cantidad
xr = xu-((funcion(xu)*(xi-xu))/(funcion(xi)-funcion(xu)));
fprintf("%d\t", i)
fprintf("%.4f\t", xi)
fprintf("%.4f\t", xu)
fprintf("%.4f\t", xr)
if funcion(xi)*funcion(xr)<0
fprintf("%.4f\t", funcion(xi)*funcion(xr))
xu = xr;
elseif funcion(xi)*funcion(xr)>0
fprintf("%.4f\t", funcion(xi)*funcion(xr))
xi = xr;
elseif funcion(xr)==0
fprintf("%s","raiz encontrada")
break
endif
fprintf("\n")
i++;
endwhile
fprintf(" la raiz aproximada es: %.4f \n", xr)
else
fprintf("%s","no se puede resolver por este metodo")
endif
##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

También podría gustarte