Вы находитесь на странице: 1из 5

Métodos Numéricos

Alumnos:
-Vargas Espinoza, Jimena ………….17070112
-Ayala Mendoza, Angel ……………..15070103

Método de Newton-Raphson
Programación SciLab

function y=f(x)
y=exp(-x)-x;
endfunction

function y=df(x)
y=-exp(-x)-1;
endfunction
clc()
x0=input("\n Ingrese el limite inferior para el itervalo: ");
tol=input("\n Ingrese la tolerancia deseada: ");
i=1;
ea(1)=100;
x(1)=x0;
while abs(ea(i))>=tol;
x(i+1)=x(i)-f(x(i))/df(x(i));
ea(i+1)=abs((x(i+1)-x(i))/x(i+1)*100);
i=i+1;
end
printf(' i \t X(i) Error aprox (i) \n');
for j=1:i;
printf('%2d \t %11.7f \t %7.3f \n',j-1,x(j),ea(j));
end

Ejemplo No 1:
Función: e-x –x
\n Ingrese el limite inferior para el itervalo: 0

\n Ingrese la tolerancia deseada: 0.0001

Lima, 08 de Abril de 2019


i X(i) Error aprox (i)

0 0.0000000 100.000

1 0.5000000 100.000

2 0.5663110 11.709

3 0.5671432 0.147

4 0.5671433 0.000

Método de Bisección
Programación SciLab

function y=f(x)
y=exp(-x)-x;
endfunction
clc()
xl=input("\n Ingrese el limite inferior para el itervalo: ");
xu=input("\n Ingrese el limite superior para el itervalo: ");
tol=input("\n Ingrese la tolerancia deseada: ");
nmax=input("\n Ingrese el numero de iteraciones maximas: ");
xr = xl;
n = 0;
while 1
xa = xr;
xr = (xl+xu)/2;
ea = abs((xr-xa)/xr)*100;
r = feval(xr,f);
a = feval(xl,f);
b = feval(xu,f);
if( a*r < 0 ) then
xu = xr;
else

Lima, 08 de Abril de 2019


xl = xr;
end
n = n + 1;
if(ea < tol | n == nmax ) then
break
end
end
printf("\n Valor aproximado:%12.6f\n", xr);
printf("Iteraciones: %d \n", n);
printf("Error Absoluto: %f por ciento \n", ea);

Ejemplo No 2:
Función: e-x –x
\n Ingrese el limite inferior para el itervalo: 0

\n Ingrese el limite superior para el itervalo: 1

\n Ingrese la tolerancia deseada: 0.0001

\n Ingrese el numero de iteraciones maximas: 30

Valor aproximado: 0.567143

Iteraciones: 21

Error Absoluto: 0.000084 por ciento

Lima, 08 de Abril de 2019


Método de Falsa Posición
Programación SciLab

function y=f(x)
y=exp(-x)-x;
endfunction
clc()
xl=input("\n Ingrese el limite inferior para el itervalo: ");
xu=input("\n Ingrese el limite superior para el itervalo: ");
tol=input("\n Ingrese la tolerancia deseada: ");
nmax=input("\n Ingrese el numero de iteraciones maximas: ");
xr = xu;
n = 0;
while 1
xa = xr;
xr = xu-(b*(xl-xu)/(a-b));
ea = abs((xr-xa)/xr)*100;
r = feval(xr,f);
a = feval(xl,f);
b = feval(xu,f);
if( a*r < 0 ) then
xu = xr;
else
xl = xr;
end
n = n + 1;
if(ea < tol | n == nmax ) then
break
end
end
printf("\n Valor aproximado:%12.6f\n", xr);
printf("Iteraciones: %d \n", n);
printf("Error Absoluto: %f por ciento \n", ea);

Ejemplo No 3:
Función: e-x –x
\n Ingrese el limite inferior para el itervalo: 0

\n Ingrese el limite superior para el itervalo: 1

\n Ingrese la tolerancia deseada: 0.0001

\n Ingrese el numero de iteraciones maximas: 40

Lima, 08 de Abril de 2019


Valor aproximado: 0.567143

Iteraciones: 8

Error Absoluto: 0.000013 por ciento

Lima, 08 de Abril de 2019

Вам также может понравиться