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
0