plot the solution obtained from desolve_system

56 views
Skip to first unread message

Flavio Coelho

unread,
Jul 10, 2013, 4:26:02 PM7/10/13
to sage-s...@googlegroups.com
Hi,

I am trying to plot the solutions the following system of ODEs

var('t')
A = function('A',t)
B = function('B',t)
de1 = diff(A,t) == -k1*A+k2*B
de2 = diff(B,t) == k1*A-k2*B
sol = desolve_system([de1,de2],[A,B],ics=[500,0])
show(sol)
solA, solB = sol[0].rhs(), sol[1].rhs()
plot((solA,solB),(t,0,50))

however the solution includes A(0) and B(0) as seen below:

[A(t)=111(6A(0)5B(0))e(1120t)+511A(0)+511B(0),B(t)=111(6A(0)5B(0))e(1120t)+611A(0)+611B(0)]
How do specify the initial contidions so that my plot command above works? Now I am getting the following error:
verbose 0 (2424: plot.py, generate_plot_points) WARNING: When plotting,
failed to evaluate function at 200 points.
verbose 0 (2424: plot.py, generate_plot_points) Last error message:
'unable to simplify to float approximation'
verbose 0 (2424: plot.py, generate_plot_points) WARNING: When plotting,
failed to evaluate function at 200 points.
verbose 0 (2424: plot.py, generate_plot_points) Last error message:
'unable to simplify to float approximation'

kcrisman

unread,
Jul 10, 2013, 5:20:05 PM7/10/13
to sage-s...@googlegroups.com


On Wednesday, July 10, 2013 4:26:02 PM UTC-4, Flavio Coelho wrote:
Hi,

I am trying to plot the solutions the following system of ODEs

var('t')
A = function('A',t)
B = function('B',t)
de1 = diff(A,t) == -k1*A+k2*B
de2 = diff(B,t) == k1*A-k2*B

We're missing some info here.  If I make these variables, the commands below don't work at all, so they must be constants of some kind.  Can you give values?  (Or I can use sol = desolve_system([de1,de2],[A,B],ics=[500,0],ivar=t) as my command.)

 
sol = desolve_system([de1,de2],[A,B],ics=[500,0])
show(sol)
solA, solB = sol[0].rhs(), sol[1].rhs()
plot((solA,solB),(t,0,50))

however the solution includes A(0) and B(0) as seen below:

[A(t)=111(6A(0)5B(0))e(1120t)+511A(0)+511B(0),B(t)=111(6A(0)5B(0))e(1120t)+611A(0)+611B(0)]
How do specify the initial contidions so that my plot command above works? Now I am getting the following error:

I'd try

sol = desolve_system([de1,de2],[A,B],ics=[0,500,0],ivar=t)

because t=0 is probably what you implicitly wanted.  An initial condition system doesn't necessarily start at t=0, just wherever your information is.

kcrisman

unread,
Jul 10, 2013, 5:38:43 PM7/10/13
to sage-s...@googlegroups.com
I've opened http://trac.sagemath.org/sage_trac/ticket/14877 for the potential confusion of having the "wrong number of initial conditions".
Reply all
Reply to author
Forward
0 new messages