Ask Your Question

Groenendael72's profile - activity

2016-12-31 22:11:32 +0200 received badge  Student (source)
2014-02-20 18:31:21 +0200 received badge  Editor (source)
2014-02-20 18:26:00 +0200 asked a question desolve_rk4 cannot handle a piecewise function

I am trying to get a numeric solution to a differential equation involving a function that is piecewise (actually defined using an if/else statement). I successfully generated a slopefield using the lambda function, but desolve_rk4 seemingly cannot cope with this syntax. It seems to me that a numeric solver should be able to handle a function defined this way, but perhaps I am just doing something wrong?

Code:

var('t')
def f(t):
    if t<5:
        return 3
    else:
        return 0
V=function('V',t)
desolve_rk4(lambda t,V: ((f)-V)/(2.3*1.2),V, ics=(0,0),ivar=t)