Hi everybody,

I am starting to learn how to solve ODEs analytically/numerically with Sage, which to my understanding, implies using Maxima functions. I followed the docu here: http://maxima.sourceforge.net/docs/manual/en/maxima_22.html.

Now, i wanted to solve analytically the following equation:
cm*dV/dt =  iM - gL*(v(t) - EL) , where cm, iM, gL and EL are parameters.

This works nicely assuming that these parameters are constant. However, I would like to solve the equation for iM being a time-dependent function (for example a square/sin pulse). Something like this:

cm*dV/dt = iM(t) - gL*(v(t) - EL), where iM(t) is the time-dependent function

# define independent/dependent variables
sage: t=var('t')
sage: v=function('v',t)

# equation parameters
sage: iM, gL, EL, cm = var('iM, gL, EL, cm')

# define equation
sage: eq = diff(v,t) - 1/cm*(iM-gL*(v-EL) ) == 0

# solve it analytically
sage: desolve(de=eq, dvar=v, ivar=t, ics=[0,-65])

Then Sage returns this:->  (EL*gL*e^(gL*t/cm) + (e^(gL*t/cm) - 1)*iM - (EL 
+65)*gL)*e^(-gL*t/cm)/gL

which is correct.

If I now define a function of the form:

def pulse(tonset, tdur, amp):
    """ returns a square pulse as a function of t, f(t)
    the pulse is defined as follows:
    tonset -- start of pulse
    tdur   -- duration of pulse
    amp    -- amplitude of pulse
    """
    t=var('t') # do i need this?

    f(t)= amp*(sign(t-tonset)/2-sign(t-tonset-tdur)/2)
    return f

I tried to define iM as a function of t
sage: mypulse = pulse(tonset =5, tdur = 10, amp =2 )

and redefined the equation (not sure if I wrote correctly
sage: eq = diff(v,t) - 1/cm*(mypulse - gL*(v-EL) ) == 0
sage: eq = diff(v,t) - 1/cm*(diff(mypulse,t) - gL*(v-EL) ) == 0 # this is probably wrong

In either case, Sage returns the same error:
TypeError: unable to make sense of Maxima expression 'v(t)=-e^-(t*gL/cm)*(at(integrate((EL*gL+signum(t-5)-signum(t-13))*e^(t*gL/cm),t),[t=0,v(t)=-65])-integrate((EL*gL+signum(t-5)-signum(t-13))*e^(t*gL/cm),t)+65*cm)/cm' in Sage

What I am missing here. I got a similar problem with desolve_laplace. Should I use another ODE solver?

I got it running with Mathematica (using DSolve), but it would be great to have it with Sage!

Thanks a lot in advance

Jose.

--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to