On Tue, Feb 5, 2013 at 6:46 AM, Francesco Paparella
<
francesco...@unile.it> wrote:
> Is there any way to teach sympy to yield a (useful and correct) result when
> convolving two piecewise functions?
> Here is an example (SymPy 0.7.2-git)
>
> --------------------------------------------------------------------------------------------------------------------------------------
> In [1]: f = Piecewise((0, x<=-1), (Rational(1,2), x<1), (0, True))
> In [2]: integrate(f.subs(x, x-y, simultaneous=True)*f(x), y)
> Out[2]:
> ⎧ 0 for x ≤ -1
> ⎪
> ⎪⎧0 for x - y ≤ -1 for x < 1
> ⎪⎪
> ⎪⎪y
> ⎨⎨─ for x - y < 1
> ⎪⎪4
> ⎪⎪
> ⎪⎩0 otherwise
> ⎪
> ⎩ 0 otherwise
> ---------------------------------------------------------------------------------------------------------------------------------------
> Note that I have used f.subs(x, x-y, simultaneous=True) because
> piecewise-defined functions seem to
> have memory of the name of the dummy variable used to define them.
Why do you have to do this? It seems to be the same without simultaneous=True.
Probably this would require something like
http://code.google.com/p/sympy/issues/detail?id=2128. Also, we don't
currently have any kinds of algorithms to simplify the piecewise
conditions.
One idea is that in that issue it is noted that integration of
Heaviside functions works. So maybe you could try that.
Unfortunately. Piecewise.rewrite(Heaviside) is not implemented yet, so
you'll have to do it manually. For example, your function is
Heaviside(x + 1)/2 - Heaviside(x - 1)/2 (except at the points -1 and
1, because of the way Heaviside is defined at 0). Integrating the
convolution of that gives a complex piecewise expression, which is
based on whether |y| is less than or greater than |x + 1| and/or |x -
1|. It's actually more complex than it looks, because it gives some
(probably) singular G-functions in the cases where |y| = |x + 1| or |x
- 1|.
This might actually not be useful to you, since things get complex
quite fast, but you can see if it leads you anywhere.
Aaron Meurer
>
> If I am not mistaken, the correct and useful result should be
>
> (2-abs(x))/4, abs(x)<2
> 0, otherwise
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
sympy+un...@googlegroups.com.
> To post to this group, send email to
sy...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/sympy?hl=en.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>