ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 18 Jan 2012 08:36:09 -0600ODE solving questionhttp://ask.sagemath.org/question/8642/ode-solving-question/I'm stumped here. I am implementing a parachute model for use in my modeling class and am using a nice ODE class devised by oddrobot and modified by Jason Grout. To model the opening of the parachute, I need to make a parameter's value depend on the height of the parachutist. But, the if..then statements in my code appear to be getting ignored. What am I missing here?
Here is what I'm doing. (Note that DESolution is a command in the ODE solving routine that I'm using.)
var('x,v')
g1=9.81
def g(x,v):
if x>50:
return(-g1-0.3*abs(v)*v)
elif x>0:
return(-g1-2*abs(v)*v)
else:
return(0)
def f(x,v):
if x>0:
return(v)
else:
return(0)
F=[f(x,v),g(x,v)]
solution=DESolution(F,[t,0,40],[(x,100),(v,0)])
solution.coordinates(['red','blue'])
The complete code is published at:
http://sage.maa.org/home/pub/104/
Wed, 18 Jan 2012 07:17:25 -0600http://ask.sagemath.org/question/8642/ode-solving-question/Answer by Jason Grout for <p>I'm stumped here. I am implementing a parachute model for use in my modeling class and am using a nice ODE class devised by oddrobot and modified by Jason Grout. To model the opening of the parachute, I need to make a parameter's value depend on the height of the parachutist. But, the if..then statements in my code appear to be getting ignored. What am I missing here?</p>
<p>Here is what I'm doing. (Note that DESolution is a command in the ODE solving routine that I'm using.)</p>
<pre><code>var('x,v')
g1=9.81
def g(x,v):
if x>50:
return(-g1-0.3*abs(v)*v)
elif x>0:
return(-g1-2*abs(v)*v)
else:
return(0)
def f(x,v):
if x>0:
return(v)
else:
return(0)
F=[f(x,v),g(x,v)]
solution=DESolution(F,[t,0,40],[(x,100),(v,0)])
solution.coordinates(['red','blue'])
</code></pre>
<p>The complete code is published at:</p>
<p><a href="http://sage.maa.org/home/pub/104/">http://sage.maa.org/home/pub/104/</a></p>
http://ask.sagemath.org/question/8642/ode-solving-question/?answer=13142#post-id-13142Thanks for posting your question here.
Basically, change two lines:
`def g(x,v):` to `def g(x,v,t):` (make the function also take time as the last input, even if we don't use it). You can even make t have a default value so you don't actually have to specify it when calling: `def g(x,v,t=0):`
`F=[v,g(x,v)]` to `F=[v,g]` (don't call the function g when you define F; that sets F to the *result* of g. Instead, just pass the function itself in.
Wed, 18 Jan 2012 07:27:59 -0600http://ask.sagemath.org/question/8642/ode-solving-question/?answer=13142#post-id-13142Comment by calc314 for <p>Thanks for posting your question here. </p>
<p>Basically, change two lines:</p>
<p><code>def g(x,v):</code> to <code>def g(x,v,t):</code> (make the function also take time as the last input, even if we don't use it). You can even make t have a default value so you don't actually have to specify it when calling: <code>def g(x,v,t=0):</code></p>
<p><code>F=[v,g(x,v)]</code> to <code>F=[v,g]</code> (don't call the function g when you define F; that sets F to the <em>result</em> of g. Instead, just pass the function itself in.</p>
http://ask.sagemath.org/question/8642/ode-solving-question/?comment=20503#post-id-20503That did it! Thanks!Wed, 18 Jan 2012 08:36:09 -0600http://ask.sagemath.org/question/8642/ode-solving-question/?comment=20503#post-id-20503