Ask Your Question

# solving a system of DEs numerically and plotting the solution

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 close merge delete

## 1 Answer

Sort by » oldest newest most voted

Try this:

ans=desolve_system_rk4(des, [s,i,r], ics=[0, 1, 0.00000127,0], ivar=t, end_points=20)
ts=[[a,a] for a in ans]
ti=[[a,a] for a in ans]
tr=[[a,a] for a in ans]
line(ts)+line(ti,color='red')+line(tr,color='green')

more

## Your Answer

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

Add Answer

## Stats

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

Seen: 512 times

Last updated: Nov 03 '14