Matlab - runge kutta como graficar x,y

 
Vista:

runge kutta como graficar x,y

Publicado por yusmary martinez (3 intervenciones) el 08/04/2018 13:09:43
Disculpen pero como harian para graficar esto? tengo un rato intentado pero me arroja error cuando pongo el comando plot()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
%% runge kutta
x1=1
y1=0
h=0.05
t(1)=0;x(1)=x1;y(1)=y1
x=y
y=0.1*(1-x^2)*y-x
f=x;
g=y;
F=inline(f,'t','x','y');
G=inline(g,'t','x','y');
for i=1
    t(i+1)=t(1)+i*h
    k(1)=h*F(t(i),x(i),y(i));
    l(1)=h*G(t(i),x(i).y(i))
    k(2)=h*F(t(i)+h/2,x(i)+k(1)/2,y(i)+l(1)/2);
    l(2)=h*G(t(i)+h/2,x(i)+k(1)/2,y(i)+l(1)/2);
    k(3)=h*F(t(i)+h/2,x(i)+k(2)/2,y(i)+l(2)/2);
    l(3)=h*G(t(i)+h/2,x(i)+k(2)/2,y(i)+l(2)/2);
    k(4)=h*F(t(i)+h,x(i)+k(3),y(i)+l(3));
    l(4)=h*G(t(i)+h,x(i)+k(3),y(i)+l(3));
    x(i+1)=x(i)+(1/6)*(k(1)+x*k(2)+x*k(3)+k(4));
    y(i+1)=y(i)+(1/6)*(l(1)+2*l(2)+2*l(3)+l(4));
end
plot(t,x,'r-',t,y,'b-')
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de JOSE JEREMIAS CABALLERO
Val: 6.975
Oro
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

runge kutta como graficar x,y

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 08/04/2018 22:29:56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
%% runge kutta
x1=1
y1=0
h=0.05
t(1)=0;x(1)=x1;y(1)=y1
syms X Y
X=Y
Y=0.1*(1-X^2)-X
f=X;
g=Y;
F=inline(f,'t','X','Y')
G=inline(g,'t','X','Y')
for i=1
    t(i+1)=t(1)+i*h
    k(1)=h*F(t(i),x(i),y(i));
    l(1)=h*G(t(i),x(i),y(i))
    k(2)=h*F(t(i)+h/2,x(i)+k(1)/2,y(i)+l(1)/2);
    l(2)=h*G(t(i)+h/2,x(i)+k(1)/2,y(i)+l(1)/2);
    k(3)=h*F(t(i)+h/2,x(i)+k(2)/2,y(i)+l(2)/2);
    l(3)=h*G(t(i)+h/2,x(i)+k(2)/2,y(i)+l(2)/2);
    k(4)=h*F(t(i)+h,x(i)+k(3),y(i)+l(3));
    l(4)=h*G(t(i)+h,x(i)+k(3),y(i)+l(3));
    x(i+1)=x(i)+(1/6)*(k(1)+x(i)*k(2)+x(i)*k(3)+k(4));
    y(i+1)=y(i)+(1/6)*(l(1)+2*l(2)+2*l(3)+l(4));
end
whos t x y
plot(t,x,'r-',t,y,'b-'
)


Saludos
JOSE JEREMIAS CABALLERO
Asesor de Proyectos con Matlab
Servicios de programación matlab


http://matlabcaballero.blogspot.com
https://www.facebook.com/matlabcaballero
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

runge kutta como graficar x,y

Publicado por yusmary martinez (3 intervenciones) el 08/04/2018 22:44:12
Muchas Gracias. Ya podre seguir avanzando :)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar