ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 08 Aug 2018 13:41:12 +0200Solved: Why does integrate(psi(y)*f(y),y) return an error but integrate(psi(t,y)*f(t,y),y) works?https://ask.sagemath.org/question/43287/solved-why-does-integratepsiyfyy-return-an-error-but-integratepsityftyy-works/Hi there,
I am trying get an symbolic expression for the convolution
$$ (\psi \star f)(x) := \int\limits_{\mathbb{R}} \psi(x-y) f(y) {d y} $$
of two functions
$
f, \psi: \mathbb{R} \to \mathbb{R}
$
as follows:
<code>
var('y') <br>
psi = function('psi')(y) <br>
f = function('f')(y) <br>
integrate(psi(x-y)*f(y),y)
</code>
upon which I get the error message
> RuntimeError: ECL says: Error executing code in Maxima:
If I add an extra argument to the two functions and define them as
$$ f, \psi : \mathbb{R} \times \mathbb{R} \to \mathbb{R} $$
as follows:
<code>
var('t') <br>
psi = function('psi')(t,y) <br>
f = function('f')(t,y) <br>
integrate(psi(t,x-y)*f(t,y),y)
</code>
there is a surprise, *it suddenly works!*
I get the desired symbolic expression on which I can run diff(..,x) and all the other built-in functions.
**TL;DR**
Why does <code>integrate(psi(y)*f(y),y)</code> return an error?
**Solution**
Use sympy backend for symbolic integration as in
<code>integrate(psi(x-y)*f(y),y, algorithm="sympy")</code>hausdorffWed, 08 Aug 2018 13:41:12 +0200https://ask.sagemath.org/question/43287/A symbolic convolution of arbitrary functionshttps://ask.sagemath.org/question/8507/a-symbolic-convolution-of-arbitrary-functions/In [this manual](http://www.sagemath.org/doc/constructions/calculus.html#convolution) it is described how to get a symbolic result of "the convolution of any piecewise defined function with another". However, when I try this with functions like exponent, this does not work:
x = PolynomialRing(QQ, 'x').gen()
f = Piecewise([[(0,1),exp(x)]])
f.convolution(f)
I get an error "RuntimeError: Symbolic Ring still using old coercion framework"
If I use a 'RR' ring instead of 'QQ', Piecewise() returns another error "TypeError: cannot coerce arguments: __call__() takes exactly 1 positional argument (0 given)"
I have 2 questions:
1. Is there a way to get a function, which represent convolution of a gaussian function and a decaying exponent (and, generally, any functions)? I want to fit my data with such a function.
2. How to get a symbolical convolution of functions with parameters (they should be assumed to be constants during convolution computation)?ADuC812Thu, 24 Nov 2011 00:01:36 +0100https://ask.sagemath.org/question/8507/convolution got the wrong resulthttps://ask.sagemath.org/question/8534/convolution-got-the-wrong-result/Hi, English is not my mother language, so I am trying to make myself clear. And sorry for my grammer mistakes.
I am new to sage and trying to do convolution:f(x) * g(x)?
>f(x) = 2, -2 < x < 2; f(x) = 0, x < -2 or x > 2
>g(x) = 3/4, 0 < x < 2; g(x) = 0, x < 0 or x > 2
I use the following code to do the job:
x = PolynomialRing(QQ,'x').gen()
f = Piecewise([[(-2, 2), 2 * x^0]])
show(f)
g = Piecewise([[(0, 2), 3/4 * x^0]])
show(g)
m = g.convolution(f)
show(m)
I think I am sure the result should be:
>3/2 * x + 3, -2 < x < 0;
>3, 0 < x < 2
>-3/2 * x + 6, 2 < x < 4
>0, x < -2 or x > 4
but it comes out that when 0 < x < 2, the result is 6, which should be 3. There must be something wrong, but I can not figure out. So I am here to ask for help.
Thank you.yideeyTue, 06 Dec 2011 09:39:30 +0100https://ask.sagemath.org/question/8534/Convolving two functions doesn't work as expectedhttps://ask.sagemath.org/question/10019/convolving-two-functions-doesnt-work-as-expected/Hi all, I'm trying to convolve two functions as follows:
`forget()` <br>
`x = PolynomialRing(QQ, 'x').gen()` <br>
`f1 = Piecewise([[(-1, 1), 1*x^0]])` <br>
`f2 = Piecewise([[(0, 1), x], [(1, 2), -x + 2]])` <br>
`g = f2.convolution(f1)` <br>
`Q = g.plot(rgbcolor=(1,1,0), figsize = 4);` <br>
`g`
I get that g is given by:
> Piecewise defined function with 4 parts, [[(-1, 0), 1/2\*x^2 + x +1/2], [(0, 1), -1/2\*x^2 + 3\*x], [(1, 2), -1/2\*x^2 - x + 4], [(2, 3), 1/2\*x^2 -
3\*x + 9/2]].
Whereas, if computed manually, g is given by:
> Piecewise defined function with 3 parts, [[(-1, 0),
0.5\*x^2 + x + 0.5], [(0, 2),
-0.5\*x^2 + x + 0.5], [(2, 3),
0.5\*x^2 - 3\*x + 4.5]
Why doesn't the one computed by sage match the correct function?
ThisisnotanidSat, 13 Apr 2013 18:31:30 +0200https://ask.sagemath.org/question/10019/