Ask Your Question
0

solving a system of DEs numerically and plotting the solution

asked 2014-11-03 14:32:05 -0600

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
1

answered 2014-11-03 15:17:39 -0600

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]
line(ts)+line(ti,color='red')+line(tr,color='green')
edit flag offensive delete link more

Comments

Thanks for the help.

strangelove1661 gravatar imagestrangelove1661 ( 2014-11-03 17:52:38 -0600 )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

Stats

Asked: 2014-11-03 14:32:05 -0600

Seen: 433 times

Last updated: Nov 03 '14