Professional Documents
Culture Documents
Tarea1-25/01/2012
A)
Carlos A. Aguilar A.
Tarea1-25/01/2012
Carlos A. Aguilar A.
Tarea1-25/01/2012
x2(1)=0;
for n=2:((b-a)/h)+1
k1=h*x2(n-1);
l1=h*[u*(1-x1(n-1)^2)*x2(n-1)-x1(n-1)+A*sin(w*t(n-1))];
k2=h*(x2(n-1)+(1/2)*l1);
l2=h*[u*(1-(x1(n-1)+(1/2)*k1)^2)*(x2(n-1)+(1/2)*l1)-(x1(n-1)+(1/2)*k1)+A*sin(w*(t(n1)+(1/2)*h))];
k3=h*[x2(n-1)+(1/2)*l2];
l3=h*[u*(1-(x1(n-1)+(1/2)*k2)^2)*(x2(n-1)+(1/2)*l2)-(x1(n-1)+(1/2)*k2)+A*sin(w*(t(n1)+(1/2)*h))];
k4=h*(x2(n-1)+l3);
l4=h*[u*(1-(x1(n-1)+k3)^2)*(x2(n-1)+l3)-(x1(n-1)+k3)+A*sin(w*(t(n-1)+h))];
x1(n)=x1(n-1)+(1/6)*(k1+2*k2+2*k3+k4);
x2(n)=x2(n-1)+(1/6)*(l1+2*l2+2*l3+l4);
end
hold on
if i==1
plot(t,x1,'r--')
end
if i==2
plot(t,x1,'k:')
end
if i==3
plot(t,x1)
end
end
legend('h=0.1','h=0.01','h=0.001')
Title('Metodo de Runge-Kutta para Resolver EDO de Segundo Orden')
xlabel('Tiempo(t)')
ylabel('Solucion(x)')
Carlos A. Aguilar A.
B)
Tarea1-25/01/2012
Carlos A. Aguilar A.
Tarea1-25/01/2012
Carlos A. Aguilar A.
Tarea1-25/01/2012
x1=a:h:b;
x2=a:h:b;
%Condiciones iniciales
x1(1)=2;
x2(1)=0;
for n=2:((b-a)/h)+1
k1=h*x2(n-1);
l1=h*[u*(1-x1(n-1)^2)*x2(n-1)-x1(n-1)];
k2=h*(x2(n-1)+(1/2)*l1);
l2=h*[u*(1-(x1(n-1)+(1/2)*k1)^2)*(x2(n-1)+(1/2)*l1)-(x1(n-1)+(1/2)*k1)];
k3=h*[x2(n-1)+(1/2)*l2];
l3=h*[u*(1-(x1(n-1)+(1/2)*k2)^2)*(x2(n-1)+(1/2)*l2)-(x1(n-1)+(1/2)*k2)];
k4=h*(x2(n-1)+l3);
l4=h*[u*(1-(x1(n-1)+k3)^2)*(x2(n-1)+l3)-(x1(n-1)+k3)];
x1(n)=x1(n-1)+(1/6)*(k1+2*k2+2*k3+k4);
x2(n)=x2(n-1)+(1/6)*(l1+2*l2+2*l3+l4);
end
hold on
if i==1
plot(t,x1,'r--')
end
if i==2
plot(t,x1,'k:')
end
if i==3
plot(t,x1)
end
end
legend('h=0.1','h=0.01','h=0.001')
Title('Metodo de Runge-Kutta para Resolver EDO de Segundo Orden')
xlabel('Tiempo(t)')
ylabel('Solucion(x)')