You are on page 1of 4

CURSO: Metodos Numericos

ALUMNO: Huarca Cusi Wilian Nehemias

Serie de Taylor y Mtodo de Runge-Kutta

DOCENTE: Luz Elizabeth Huanchi Mamani

SEMESTRE: V

JULIACA-PER
2017
2
INGENIERIA EN ENERGIAS RENOVABLES
METODOS NUMERICOS SEMESTRE V

Serie de Taylor

clear all
clc
syms x
fun=input('f(x): ');
f = inline(fun);
x1 = input('X(i): ');
x2 = input('X(i+1): ');
n = input('Nmero de Orden: ');
h = abs(x2 - x1);
v1 = f(x1);
v2 = f(x2);
et = abs((v2 - v1)/v2 * 100);
X(1,:) = [0 v1 0 et];
for i=1:n
X(i+1,1) = i;

D = diff(fun,i);
d1=inline(D);
d=d1(x1);
v1= v1+(d*((h^i)/factorial(i)));
X(i+1,2) = v1;

et=abs(((v2-v1)/v2)*100);
X(i+1,4) = et;

ea = abs((X(i+1,2)-X(i,2))/X(i,2)*100);
X(i+1,3) = ea;

if ea <=10^(-1)
break
end
end
X
ejercicio
Ejecutando para una funcin cualesquiera

f(x): sqrt(1+(cos(x))^2)
X(i): 5
X(i+1): 6
Nmero de Orden: 3

X =

0 1.0395 0 25.0215
1.0000 1.3011 25.1753 6.1454
2.0000 1.6718 28.4882 20.5921
3.0000 1.4040 16.0171 1.2768
3
INGENIERIA EN ENERGIAS RENOVABLES
METODOS NUMERICOS SEMESTRE V
Mtodo de Runge-Kutta
PROGRAMA EN MATLAB DE RUNGE-KUTTA DE ORDEN DOS.

function f
fprintf('\n \tRESOLUCION DE ECUACIONES DIFERENCIALES POR MEDIO RUNGE-
KUTTA DE ORDEN 4\n')
f=input('\n Ingrese la ecuacion diferencial dy/dx=\n','s');
x0=input('\n Ingrese el primer punto x0:\n');
x1=input('\n Ingrese el segundo punto x1:\n');
y0=input('\n Ingrese la condicion inicial y(x0):\n');
n=input('\n Ingrese el numero de pasos n:\n');
h=(x1-x0)/n;
xs=x0:h:x1;
fprintf('\n''it x0 y(x1)');
for i=1:n
it=i-1;
x0=xs(i);
x=x0;
y=y0;
k1=h*eval(f);
x=xs(i+1);
y=y0+k1;
k2=h*eval(f);
y0=y0+(k1+k2)/2;
fprintf('\n%2.0f%10.6f%10.6f\n',it,x0,y0);
end
fprintf('\n El punto aproximado y(x1) es = %8.6f\n',y0);

Programa de Runge-Kutta de orden cuatro.

function f
fprintf('\n \tRESOLUCION DE ECUACIONES DIFERENCIALES POR MEDIO RUNGE-
KUTTA DE ORDEN 4\n')
f=input('\n Ingrese la ecuacion diferencial\n','s');
x0=input('\n Ingrese el primer punto x0:\n');
x1=input('\n Ingrese el segundo punto x1:\n');
y0=input('\n Ingrese la condicion inicial y(x0):\n');
n=input('\n Ingrese el numero de pasos n:\n');
h=(x1-x0)/n;
xs=x0:h:x1;
fprintf('\n''it x0 y(x1)');
for i=1:n
it=i-1;
x0=xs(i);
x=x0;
y=y0;
k1=h*eval(f);
x=x0+h/2;
y=y0+k1/2;
k2=h*eval(f);
x=x0+h/2;
y=y0+k2/2;
k3=h*eval(f);
x=x0+h;
y=y0+k3;
k4=h*eval(f);
y0=y0+(k1+2*k2+2*k3+k4)/6;
fprintf('\n%2.0f%10.6f%10.6f\n',it,x0,y0);
end
4
INGENIERIA EN ENERGIAS RENOVABLES
METODOS NUMERICOS SEMESTRE V
fprintf('\n El punto aproximado y(x1) es = %8.6f\n',y0);

ejercicio
ejecutando de orden 4
RESOLUCION DE ECUACIONES DIFERENCIALES POR MEDIO RUNGE-
KUTTA DE ORDEN 4

Ingrese la ecuacion diferencial


-2*x^3+12*x^2-20*x+8.5

Ingrese el primer punto x0:


0

Ingrese el segundo punto x1:


0.5

Ingrese la condicion inicial y(x0):


1

Ingrese el numero de pasos n:


5

'it x0 y(x1)
0 0.000000 1.753950

1 0.100000 2.331200

2 0.200000 2.753950

3 0.300000 3.043200

4 0.400000 3.218750

El punto aproximado y(x1) es = 3.218750

You might also like