Re: [sympy] Re: [sage-support] Solving differential equations with unit_step?

2012-01-09 Thread Renan Birck Pinheiro
2012/1/9 Aaron Meurer 

> Thanks to Tom's Google Summer of Code project, SymPy can indeed solve
> this problem. The code is only in the git master, but will be included
> in SymPy 0.7.2.
>

This looks pretty good, I will try and compile the git version.

Thanks.
-- 
Renan Birck Pinheiro, Grupo de Microeletrônica
, Engenharia
Elétrica , UFSM  - Santa Maria,
Brazil

http://renanbirck.blogspot.com / skype: renan.ee.ufsm / (55) 91433210

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


Re: [sympy] Re: [sage-support] Solving differential equations with unit_step?

2012-01-09 Thread Aaron Meurer
And I should note that Tom's code can also compute the Laplace
transform if you want to do it that way:

In [13]: var('s')
Out[13]: s

In [14]: inverse_laplace_transform(exp(-5*s)/s, s, t)
Out[14]: Heaviside(t - 5)

Aaron Meurer

On Mon, Jan 9, 2012 at 1:36 PM, Aaron Meurer  wrote:
> Thanks to Tom's Google Summer of Code project, SymPy can indeed solve
> this problem. The code is only in the git master, but will be included
> in SymPy 0.7.2.
>
> In [3]: dsolve(Derivative(y(x),x) - Heaviside(-5 + x), y(x))
> Out[3]:
>              ⎧                               │x│
> y(x) = C₁ + 5⋅⎪           0               for ─── < 1
>              ⎪                                5
>              ⎪
>              ⎪         x                      │1│
>              ⎨         ─ - 1            for 5⋅│─│ < 1
>              ⎪         5                      │x│
>              ⎪
>              ⎪╭─╮0, 2 ⎛2, 1       │ x⎞
>              ⎪│╶┐     ⎜           │ ─⎟    otherwise
>              ⎩╰─╯2, 2 ⎝      1, 0 │ 5⎠
>
> The G function is a result of the integration algorithm.  If you are
> only dealing with real variables, you can easily see from substitution
> that it comes out to 0 for x = +/-5.  Unfortunately, we haven't yet
> implemented very good simplification of the conditions, so these will
> have to be done by hand (or using some other part of Sage).
>
> Regarding initial conditions, they aren't implemented directly in
> dsolve() yet, (see
> http://code.google.com/p/sympy/issues/detail?id=1621).  They should be
> easy to implement, though, now that we can represent derivatives at
> points. Feel free to give it a shot :) And anyway, it's not too hard
> to do it by hand.
>
> By the way, I applied for membership of the Sage group, but it
> probably won't go through as I haven't been accepted yet.  If not, can
> someone forward it?
>
> Aaron Meurer
>
> On Mon, Jan 9, 2012 at 11:55 AM, David Joyner  wrote:
>> AFAIK, Sage cannot at this time take the inverse Laplace transform of
>> something of the form e^{-5s}/s.
>>
>> I think Sympy (included with Sage) can
>> http://docs.sympy.org/dev/modules/integrals/integrals.html#integral-transforms
>> but I don't think it's been integrated together with initial conditions:
>>
> y = Function('y')
> dsolve(Derivative(y(x),x) - Heaviside(-5 + x), y(x))
>>              /
>>             |
>> y(x) = C1 +  | Heaviside(x - 5) dx
>>             |
>>            /
>>
>> (Cross-posted to sympy's support list.)
>>
>>
>> On Mon, Jan 9, 2012 at 12:39 PM, Renan Birck Pinheiro
>>  wrote:
>>> Hi,
>>>
>>> I'm trying to solve a differential equation with unit step, e.g. the
>>> equation y'(x) = U(x-5) - where U is the unit step, and the inicial
>>> condition y(0) is 0.
>>>
>>> The result is 0 for 05 (it's a simple integral of the
>>> unit step function). WolframAlpha gives the correct result [1], however sage
>>> fails:
>>>
>>> sage: x=var('x')
>>> sage: y=function('y',x)
>>>
>>> sage: desolve(diff(y,x) - unit_step(x-5),y,ics=[0,1])
>>> ---
>>> TypeError Traceback (most recent call last)
>>>
>>> /home/renan/ in ()
>>>
>>> /opt/sage/local/lib/python2.6/site-packages/sage/calculus/desolvers.pyc in
>>> desolve(de, dvar, ics, ivar, show_method, contrib_ode)
>>>     488 raise NotImplementedError, "Maxima was unable to
>>> solve this BVP. Remove the initial condition to get the general
>>> solution."
>>>     489
>>> --> 490 soln=soln.sage()
>>>     491 if is_SymbolicEquation(soln) and soln.lhs() == dvar:
>>>     492 # Remark: Here we do not check that the right hand side does
>>> not depend on dvar.
>>>
>>> /opt/sage/local/lib/python2.6/site-packages/sage/interfaces/interface.pyc in
>>> sage(self)
>>>     866 Rational Field
>>>     867 """
>>> --> 868 return self._sage_()
>>>     869
>>>     870 def __repr__(self):
>>>
>>> /opt/sage/local/lib/python2.6/site-packages/sage/interfaces/maxima_abstract.pyc
>>> in _sage_(self)
>>>    1222 import sage.calculus.calculus as calculus
>>>    1223 return
>>> calculus.symbolic_expression_from_maxima_string(self.name(),
>>> -> 1224 maxima=self.parent())
>>>    1225
>>>    1226 def _symbolic_(self, R):
>>>
>>> /opt/sage/local/lib/python2.6/site-packages/sage/calculus/calculus.pyc in
>>> symbolic_expression_from_maxima_string(x, equals_sub, maxima)
>>>    1699 return symbolic_expression_from_string(s, syms,
>>> accept_sequence=True)
>>>    1700 except SyntaxError:
>>> -> 1701 raise TypeError, "unable to make sense of Maxima expression
>>> '%s' in Sage"%s
>>>    1702 finally:
>>>    1703 is_simplified = False
>>>
>>> TypeError: unable to make sense of Maxima expression
>>> 'y(x)=-at(integrate(unit_step(x-5),x),[x=0,y(x)=1])+integrate(unit_step(x-5),x)+1'
>>> in Sage
>>>
>>> desolve_laplace is no better:
>>>
>>> sage: desolve_laplace(diff(y

Re: [sympy] Re: [sage-support] Solving differential equations with unit_step?

2012-01-09 Thread Aaron Meurer
Thanks to Tom's Google Summer of Code project, SymPy can indeed solve
this problem. The code is only in the git master, but will be included
in SymPy 0.7.2.

In [3]: dsolve(Derivative(y(x),x) - Heaviside(-5 + x), y(x))
Out[3]:
  ⎧   │x│
y(x) = C₁ + 5⋅⎪   0   for ─── < 1
  ⎪5
  ⎪
  ⎪ x  │1│
  ⎨ ─ - 1for 5⋅│─│ < 1
  ⎪ 5  │x│
  ⎪
  ⎪╭─╮0, 2 ⎛2, 1   │ x⎞
  ⎪│╶┐ ⎜   │ ─⎟otherwise
  ⎩╰─╯2, 2 ⎝  1, 0 │ 5⎠

The G function is a result of the integration algorithm.  If you are
only dealing with real variables, you can easily see from substitution
that it comes out to 0 for x = +/-5.  Unfortunately, we haven't yet
implemented very good simplification of the conditions, so these will
have to be done by hand (or using some other part of Sage).

Regarding initial conditions, they aren't implemented directly in
dsolve() yet, (see
http://code.google.com/p/sympy/issues/detail?id=1621).  They should be
easy to implement, though, now that we can represent derivatives at
points. Feel free to give it a shot :) And anyway, it's not too hard
to do it by hand.

By the way, I applied for membership of the Sage group, but it
probably won't go through as I haven't been accepted yet.  If not, can
someone forward it?

Aaron Meurer

On Mon, Jan 9, 2012 at 11:55 AM, David Joyner  wrote:
> AFAIK, Sage cannot at this time take the inverse Laplace transform of
> something of the form e^{-5s}/s.
>
> I think Sympy (included with Sage) can
> http://docs.sympy.org/dev/modules/integrals/integrals.html#integral-transforms
> but I don't think it's been integrated together with initial conditions:
>
 y = Function('y')
 dsolve(Derivative(y(x),x) - Heaviside(-5 + x), y(x))
>              /
>             |
> y(x) = C1 +  | Heaviside(x - 5) dx
>             |
>            /
>
> (Cross-posted to sympy's support list.)
>
>
> On Mon, Jan 9, 2012 at 12:39 PM, Renan Birck Pinheiro
>  wrote:
>> Hi,
>>
>> I'm trying to solve a differential equation with unit step, e.g. the
>> equation y'(x) = U(x-5) - where U is the unit step, and the inicial
>> condition y(0) is 0.
>>
>> The result is 0 for 05 (it's a simple integral of the
>> unit step function). WolframAlpha gives the correct result [1], however sage
>> fails:
>>
>> sage: x=var('x')
>> sage: y=function('y',x)
>>
>> sage: desolve(diff(y,x) - unit_step(x-5),y,ics=[0,1])
>> ---
>> TypeError Traceback (most recent call last)
>>
>> /home/renan/ in ()
>>
>> /opt/sage/local/lib/python2.6/site-packages/sage/calculus/desolvers.pyc in
>> desolve(de, dvar, ics, ivar, show_method, contrib_ode)
>>     488 raise NotImplementedError, "Maxima was unable to
>> solve this BVP. Remove the initial condition to get the general
>> solution."
>>     489
>> --> 490 soln=soln.sage()
>>     491 if is_SymbolicEquation(soln) and soln.lhs() == dvar:
>>     492 # Remark: Here we do not check that the right hand side does
>> not depend on dvar.
>>
>> /opt/sage/local/lib/python2.6/site-packages/sage/interfaces/interface.pyc in
>> sage(self)
>>     866 Rational Field
>>     867 """
>> --> 868 return self._sage_()
>>     869
>>     870 def __repr__(self):
>>
>> /opt/sage/local/lib/python2.6/site-packages/sage/interfaces/maxima_abstract.pyc
>> in _sage_(self)
>>    1222 import sage.calculus.calculus as calculus
>>    1223 return
>> calculus.symbolic_expression_from_maxima_string(self.name(),
>> -> 1224 maxima=self.parent())
>>    1225
>>    1226 def _symbolic_(self, R):
>>
>> /opt/sage/local/lib/python2.6/site-packages/sage/calculus/calculus.pyc in
>> symbolic_expression_from_maxima_string(x, equals_sub, maxima)
>>    1699 return symbolic_expression_from_string(s, syms,
>> accept_sequence=True)
>>    1700 except SyntaxError:
>> -> 1701 raise TypeError, "unable to make sense of Maxima expression
>> '%s' in Sage"%s
>>    1702 finally:
>>    1703 is_simplified = False
>>
>> TypeError: unable to make sense of Maxima expression
>> 'y(x)=-at(integrate(unit_step(x-5),x),[x=0,y(x)=1])+integrate(unit_step(x-5),x)+1'
>> in Sage
>>
>> desolve_laplace is no better:
>>
>> sage: desolve_laplace(diff(y,x) - unit_step(x-5),y,ics=[0,1])
>> ---
>> TypeError Traceback (most recent call last)
>>
>> /home/renan/ in ()
>>
>> /opt/sage/local/lib/python2.6/site-packages/sage/calculus/desolvers.pyc in
>> desolve_laplace(de, dvar, ics, ivar)
>>     657 if str(soln).strip() == 'false':
>>     658 raise NotImplementedEr