The curious case of Convolve function
I don't know why Mathematica returns the incorrect result, but it may be helpful to have the correct result so as to find the origin of the bug.
To find the correct result, one may generate the first few convolutions for $n=1,2,\cdots,20$ and then use FindSequenceFunction
to get the general formula for arbitrary $n$. The result is
-((4^(-1 + n) x^(1 - 2 n) Gamma[-(1/2) + n] (Log[4] - 2 Log[x] + PolyGamma[0, -(1/2) + n] - PolyGamma[0, n]))/(Sqrt[\[Pi]] Gamma[n]))
which, for $n=1,2,3,\cdots$ evaluates to
(2 Log[x])/x, (-2 + 4 Log[x])/x^3, (-7 + 12 Log[x])/x^5, ...
The Latex formula for arbitrary $n$ reads $$ \frac{4^{n-1} x^{1-2 n} \Gamma \left(n-\frac{1}{2}\right) \left(-\psi ^{(0)}(n)+\psi ^{(0)}\left(n-\frac{1}{2}\right)-2 \log \left(\tfrac12x\right)\right)}{\sqrt{\pi }\ \Gamma (n)} $$
Here is the email I just received from Wolfram product support regarding this issue:
RE: [CASE:4209568] Your Wolfram Product Feedback
Hello *******,
Thanks for contacting Wolfram Technical Support.
It does appear that it is not behaving properly. I have forwarded an issue report to our developers with the information you provided. I also included your contact information in my report.
Furthermore, I would request you to report such issues to the Wolfram Technical Support (http://support.wolfram.com) so that it can be forwarded to the developer team.
Please do not hesitate to contact us if you have any further queries.
So it does look like the bug will hopefully be resolved in the next version.
In the meantime, it's still unclear for me that why would someone remove the [bug] tag from this question?
I don't know if this is related to the same underlying problem or if it is a different problem with Convolve
. I also realize this is not an answer per se, but it's too large to fit the limits of a comment. I'm posting it here in case it may be related somehow to the strange behavior the OP encountered. When I was working with Convolve
a while ago, I identified the following strange behavior. It's my understanding that the convolution operation is supposed to be both commutative and associative. Below is some demonstration code that produces wildly different results when convolving three functions together. If Convolve
was commutative and associative, it should've given the same results for all 6 variants.
s[f_, t_, delay_, dispersion_] := Apply[f, {t - delay}]*UnitStep[t];
u[t_, delay_, dispersion_] := Exp[-t/(delay + dispersion)]*UnitStep[t];
v[t_, dispersion_] := Exp[-t/dispersion]/dispersion*UnitStep[t];
delayedAndDispersedConcentrationVariant1[f_, t_, delay_, dispersion_] :=
Module[{x, y},
Evaluate[Convolve[Evaluate[Convolve[s[f, x, delay, dispersion], u[x, delay, dispersion],
x, y, Assumptions -> x >= 0]], v[y, dispersion], y, t, Assumptions -> y >= 0]]];
delayedAndDispersedConcentrationVariant2[f_, t_, delay_, dispersion_] :=
Module[{x, y},
Evaluate[Convolve[Evaluate[Convolve[s[f, x, delay, dispersion], v[x, dispersion],
x, y, Assumptions -> x >= 0]], u[y, delay, dispersion], y, t, Assumptions -> y >= 0]]];
delayedAndDispersedConcentrationVariant3[f_, t_, delay_, dispersion_] :=
Module[{x, y},
Evaluate[Convolve[Evaluate[Convolve[u[x, delay, dispersion], s[f, x, delay, dispersion],
x, y, Assumptions -> x >= 0]], v[y, dispersion], y, t, Assumptions -> y >= 0]]];
delayedAndDispersedConcentrationVariant4[f_, t_, delay_, dispersion_] :=
Module[{x, y},
Evaluate[Convolve[Evaluate[Convolve[v[x, dispersion], s[f, x, delay, dispersion],
x, y, Assumptions -> x >= 0]], u[y, delay, dispersion], y, t, Assumptions -> y >= 0]]];
delayedAndDispersedConcentrationVariant5[f_, t_, delay_, dispersion_] :=
Module[{x, y},
Evaluate[Convolve[Evaluate[Convolve[u[x, delay, dispersion], v[x, dispersion],
x, y, Assumptions -> x >= 0]], s[f, y, delay, dispersion], y, t, Assumptions -> y >= 0]]];
delayedAndDispersedConcentrationVariant6[f_, t_, delay_, dispersion_] :=
Module[{x, y},
Evaluate[Convolve[Evaluate[Convolve[v[x, dispersion], u[x, delay, dispersion],
x, y, Assumptions -> x >= 0]], s[f, y, delay, dispersion], y, t, Assumptions -> y >= 0]]];
If we then compute the convolution for an arbitrary function (q[t]
in this example) using the different variants (which differ only by commutative and associative rearrangements), the resulting plots are very different.
q[t_] := Piecewise[{{0.0, t < 1.0}, {3.0, 1.0 <= t <= 2.0}, {0.0,
2.0 < t < 3.5}, {5.0, 3.5 <= t <= 5.0}, {0.0, t > 5.0}}];
Plot[q[t], {t, 0, 20}]
Plot[delayedAndDispersedConcentrationVariant1[q, t, 3.0, 2.0], {t, 0, 20}]
Plot[delayedAndDispersedConcentrationVariant2[q, t, 3.0, 2.0], {t, 0, 20}]
Plot[delayedAndDispersedConcentrationVariant3[q, t, 3.0, 2.0], {t, 0, 20}]
Plot[delayedAndDispersedConcentrationVariant4[q, t, 3.0, 2.0], {t, 0, 20}]
Plot[delayedAndDispersedConcentrationVariant5[q, t, 3.0, 2.0], {t, 0, 20}]
Plot[delayedAndDispersedConcentrationVariant6[q, t, 3.0, 2.0], {t, 0, 20}]
Variants 1 and 2 give the expected result, a delayed and smoothed version of the input function q[t]
.