Ask Your Question

solving a system of DEs numerically and plotting the solution

asked 2014-11-03 21:32:05 +0200

strangelove1661 gravatar image

Hi everyone. I want to hand Sage a system of nonlinear DEs with initial values, and I'd like a plot of the solutions. Is there a best way to do this? For example, to solve this system: ds/dt=-si, di/st=si-2i, dr/dt=2i, s(0)=1, i(0)= 0.00000127, r(0)=0, I did this in Sage:

sage: (s,i,r)=var('s,i,r')

sage: des=[-1si, si-2i, i]

sage: desolve_system_rk4(des, [s,i,r], ics=[0, 1, 0.00000127, 0], ivar=t, end_points=20)

Sage gave me a list of points, but I couldn't figure out a way to plot s, i, and r using the points it gave me. Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-11-03 22:17:39 +0200

calc314 gravatar image

Try this:

ans=desolve_system_rk4(des, [s,i,r], ics=[0, 1, 0.00000127,0], ivar=t, end_points=20)
ts=[[a[0],a[1]] for a in ans]
ti=[[a[0],a[2]] for a in ans]
tr=[[a[0],a[3]] for a in ans]
edit flag offensive delete link more


Thanks for the help.

strangelove1661 gravatar imagestrangelove1661 ( 2014-11-04 00:52:38 +0200 )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


Asked: 2014-11-03 21:32:05 +0200

Seen: 661 times

Last updated: Nov 03 '14