First time here? Check out the FAQ!

Ask Your Question
0

ODE solving question

asked 13 years ago

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/

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 13 years ago

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.

Preview: (hide)
link

Comments

That did it! Thanks!

calc314 gravatar imagecalc314 ( 13 years ago )

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: 13 years ago

Seen: 401 times

Last updated: Jan 18 '12