# My first question: When using desolve_system_rk4(), is there a way to see the plots of the dependent variables vs. the independent variable? Thanks.

 x,y,t=var('x y t')
#x=function('x',t)
P=desolve_system_rk4([x*(1-y),-y*(1-x)],[x,y],ics=[0,0.5,2],ivar=t,end_points=20)
P=P+desolve_system_rk4([x*(1-y),-y*(1-x)],[x,y],ics=[0,0.3,2],ivar=t,end_points=20)
Q=[ [i,j] for i,j,k in P]
LP=list_plot(Q)
# Q=[ [j,k] for i,j,k in P]
Q=[ [j,k] for i,j,k in P]
LP=list_plot(Q)
show(LP)
plot(x);plot(y) #Doesn't work

edit retag close merge delete

Sort by » oldest newest most voted

The command desolve_system_rk4 returns a list of lists of the form [time pt, x value, y value]. You can use a list comprehension as below to pull out coordinate pairs. Then, you can plot using the line command.

x,y,t=var('x y t')
P=desolve_system_rk4([x*(1-y),-y*(1-x)],[x,y],ics=[0,0.5,2],ivar=t,end_points=20)
tx = [[q,q] for q in P]
ty =  [[q,q] for q in P]
line(tx)+line(ty,color='red')

more

wow...I'm amazed at how helpful that is. I didn't understand how desolve_system_rk4 worked, so I couldn't work out how to get the tx and ty curves. Now I have a much better idea of both...thanks!

1

Then you should accept the answer by clicking on the check mark.