Está en la página 1de 4

UNIVERSIDAD NACIONAL DE INGENIERÍA

FACULTAD DE INGENIERÍA GEOLÓGICA, MINERA Y


METALÚRGICA

2da PRACTICA DE METODOS NUMERICOS

Curso:

 METODOS NUMERICOS

Docente:
AYALA MINA JORGE GERARDO

Integrantes:
GUEVARA CALLE, BRAYSSON
JOHNNY

2018
Metodo de la secante

%Método de la secante.
cf = input('Ingrese la función: ');
f = inline(cf);
x0 = input('Ingrese el primer valor: ');
x1 = input('Ingrese el segundo valor: ');
tol = input('Ingrese tolerancia: ');
error = 100;
n=0;
fprintf(' n x0 x1 x2 error\n');
fprintf(' %i %4.4f %4.4f --- ---\n',n,x0,x1);
while( error > tol )
n = n+1;
x2 = x1 - (x1-x0)*f(x1)/(f(x1)-f(x0));
error = abs(f(x2));
fprintf(' %i %4.4f %4.4f %4.4f %4.4f\n',n,x0,x1,x2,error);
x0 = x1;
x1 = x2;
end
FUNCION METODO DE LA FALSA SUPOSICION

%Funcion sobre método de la falsa posición.

h = input('Ingrese la función REGLA FALSA: ');


f = inline(h);
a = input('Ingrese el limite inferior del intervalo: ');
b = input('Ingrese el limite superior del intervalo: ');
tol = input('Indique la tolerancia deseada: ');

c = 0; n = 0; error = 100;
fprintf('\t n \t\ta \t\t c \t\t b \t\terror\n')

while( error > tol )


c = (a*f(b)-b*f(a))/(f(b)-f(a));
disp([n,a,c,b,error])
if( f(a)*f(c)<0 )
b = c;
else a = c;
end
error = abs(f(c));
n = n+1;
end

fprintf('Raiz encontrada con una tolerancia de %f:\n', tol)

FUNCION NEWTON RAPHSON


%Funcion sobre método newton raphson.
cf = input('Ingrese funcion a evaluar: ');
syms x f = inline(cf); derivada = diff(cf,x);
df = inline(derivada); tol = input('ingrese tolerancia: ');
error = 50; x=input('Ingrese un valor incial: ');
n=0;
disp('n xi error')
while(error>tol) n=n+1; x=x-f(x)/df(x);
error=abs(f(x)); fprintf('%i\t %3.7f\t %3.7f\n',n,x,error);
end format
long disp('--------------------------------------------------------- ');
fprintf('La solución es: %3.19f\n',x);
fprintf('El numero de iteraciones es: %i\n',n );
fprintf('El error es: %3.19f\n',error );
METODO DE LA BISECCION

%Método de la bisección.

%Método de la bisección.
clear, clc
h = input('Ingrese la función a analizar: ');
f = inline(h);
a = input('Ingrese el limite inferior del intervalo: ');
b = input('Ingrese el limite superior del intervalo: ');
tol = input('Indique la tolerancia deseada: ');

c = 0;
n = 0;
MEP = (b-a)/2;
fprintf(' \t n \t\ta \t\t c \t\t b \t\t MEP\n');

while( MEP > tol )


c = (a+b)/2;
disp([n,a,c,b,MEP])
if (f(a)*f(b)<0)
b = c;
else
a = c;
end
MEP = (b-a)/2;
n = n + 1;
end

fprintf('Raíz encontrada con una tolerancia de %f:\n\t%f\n', tol, c)

También podría gustarte