Ask Your Question
0

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.

asked 2015-03-23 18:13:06 -0500

GeoffH gravatar image

updated 2015-03-23 19:30:14 -0500

calc314 gravatar image
 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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-03-23 19:34:34 -0500

calc314 gravatar image

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[0],q[1]] for q in P]
ty =  [[q[0],q[2]] for q in P]
line(tx)+line(ty,color='red')
edit flag offensive delete link more

Comments

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!

GeoffH gravatar imageGeoffH ( 2015-03-23 23:05:31 -0500 )edit
1

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

rws gravatar imagerws ( 2015-03-24 01:58:32 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-03-23 18:13:06 -0500

Seen: 336 times

Last updated: Mar 23 '15