Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

That function desolve_system_rk4 is very badly documented. I would suggest filing a bug report on the documentation.

That said, I think the answer to your question is that you have entered the DE in the wrong way. The list of expressions you pass to the solver need to be the right hand sides of equations you get after solving for X(t) and S(t) respectively. So instead of X(t)Y for the second expression, you want $\frac{-0.01XS}{2+S}.ThenyoudontneedtodefineX(t)andS(t)$ as symbolic functions (which is I think where the error lies in your screenshot), they can remain just "variables". Here's an example:

sage: (X,S,t) = var('X,S,t')
sage: des = [0.01*X*S/(2+S), -0.01*X*S/(2+S)]
sage: desolve_system_rk4(des, [X,S], ics=[0,0.1,10], ivar=t, end_points=20)
[[0, 0.100000000000000, 10], [0.1, 0.100083368007, 9.99991663199], 
 [0.2, 0.100166805401, 9.9998331946], [0.3, 0.100250312238, 9.99974968776], 
 [0.4, 0.100333888577, 9.99966611142], [0.5, 0.100417534474, 9.99958246553], 
...
click to hide/show revision 2
No.2 Revision

That function desolve_system_rk4 is very badly documented. I would suggest filing a bug report on the documentation.

That said, I think the answer to your question is that you have entered the DE in the wrong way. The list of expressions you pass to the solver need to be the right hand sides of equations you get after solving for X(t) and S(t) respectively. So instead of X(t)Y for the second expression, you want $\frac{-0.01$$\frac{-0.01XS}{2+S}$ S}{2+S}$$ . Then you don't need to define X(t) and S(t) as symbolic functions (which is I think where the error lies in your screenshot), they can remain just "variables". Here's an example:

sage: (X,S,t) = var('X,S,t')
sage: des = [0.01*X*S/(2+S), -0.01*X*S/(2+S)]
sage: desolve_system_rk4(des, [X,S], ics=[0,0.1,10], ivar=t, end_points=20)
[[0, 0.100000000000000, 10], [0.1, 0.100083368007, 9.99991663199], 
 [0.2, 0.100166805401, 9.9998331946], [0.3, 0.100250312238, 9.99974968776], 
 [0.4, 0.100333888577, 9.99966611142], [0.5, 0.100417534474, 9.99958246553], 
...