Ask Your Question
0

ODE solving question

asked 2012-01-18 14:17:25 +0100

calc314 gravatar image

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/

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-01-18 14:27:59 +0100

Jason Grout gravatar image

Thanks 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.

edit flag offensive delete link more

Comments

That did it! Thanks!

calc314 gravatar imagecalc314 ( 2012-01-18 15:36:09 +0100 )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: 2012-01-18 14:17:25 +0100

Seen: 355 times

Last updated: Jan 18 '12