Changes between Version 5 and Version 7 of Ticket #11653


Ignore:
Timestamp:
08/06/11 08:15:33 (9 years ago)
Author:
JGuzman
Comment:

I re-formatted the text according to kcrisman (thanks a lot for the suggestion!). I will have a look to the code soon. I am looking forward to implement it. If I understood correctly, the only thing to do is to make desolve_* take the answer from Maxima to SR.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #11653 – Description

    v5 v7  
    11When trying to solve a simple ODE whose rhs contains a function, Sage fails to interpret the Maxima output.
    22
    3 Here a minimal example is 
     3Here a minimal example is
     4
    45{{{
    5 #=====================
    66sage: x=var('x') # independent variable
    77sage: v=function('v', x) # dependent variable
     8}}}
    89
    910# we define a custom square pulse function
     11{{{
    1012def pulse(tonset, tdur, amp):
    1113"""
    12 returns a square pulse as a function of x, f(x)
    13 the pulse is defined as follows: 
    14 t onset -- start of pulse 
    15 tdur   -- duration of pulse 
    16 amp    -- amplitude of pulse
    17 """
    18   f(x)= amp*(sign(x-tonset)/2-sign(x-tonset-tdur)/2)
    19   return f
     14    returns a square pulse as a function of x, f(x)
     15    the pulse is defined as follows: 
     16    t onset -- start of pulse 
     17    tdur   -- duration of pulse 
     18    amp    -- amplitude of pulse
     19    """
     20    f(x)= amp*(sign(x-tonset)/2-sign(x-tonset-tdur)/2)
     21    return f
     22}}}
    2023
    21 # create my pulse function
     24now we create a pulse function
     25{{{
    2226sage: mypulse = pulse(tonset=5, tdur=5, amp=2)
     27}}}
     28and define differential equation
     29{{{
     30sage: dvdx = diff(v, x)-x -mypulse == 0 # mypulse(x) is function
     31}}}
    2332
    24 # define differential equation s
    25 sage: dvdx = diff(v, x)-x -mypulse == 0 # mypulse(x) is function
     33To get the evolution of v we can use **desolve**
     34{{{
     35myvolt = desolve(de=dvdx, ivar=x, dvar=v, ics=[0,0])
     36}}}
    2637
    27 # get the evolution of v
    28 myvolt = desolve(de=dvdx, ivar=x, dvar=v, ics=[0,0])
    2938
    30 #=======
    3139The error message is:
    3240
    3341''TypeError: unable to make sense of Maxima expression 'v(x)=-(2*(at(integrate(signum(x-5)-signum(x-13),x),[x=0,v(x)=0]))-2*int\ egrate(signum(x-5)-signum(x-13),x)-x^2)/2' in Sage^''
    34 }}}
     42
    3543desolve_laplace leads to similar error:
     44
    3645{{{
    3746sage: desolve(de=dvdx, ivar=x, dvar=v, ics=[0,0])
     47}}}
    3848
    3949''TypeError: unable to make sense of Maxima expression 'ilt(((laplace(signum(x-5),x,?g2733)-laplace(signum(x-13),x,?g2733)+v(0)\ )*?g2733^2+1)/?g2733^3,?g2733,x)' in Sage''
    40 }}}
     50
    4151According to Nils Bruin, the problem is that Maxima 'at' function. As described in Ticket #385, this can be a problem with the implementation of 'at' for SR.
    4252
    4353Strange enough, when using other functions, the solver works nicely
     54
    4455{{{
    4556sage: dvdx = diff(v, x)-x -sin(x) == 0
     57sage: desolve(de=dvdx, ivar=x, dvar=v, ics=[0,0]"])
     58}}}
    4659
    47 sage: desolve(de=dvdx, ivar=x, dvar=v, ics=[http://trac.sagemath.org/sage_trac/log/?revs=0 "[0,0]"])
    48 }}}
    4960now Sage returns 1/2*x!^2 - cos(x) + 1
    5061