1
$\begingroup$

I am trying to do a n-round of convolution of a function. The code is posted as below. But it is not working. Is there a solution?

p[x_] := 1/(x + 1)*UnitStep[x]
p1[x_] := Convolve[p[y], p[y], y, x]
p2[x_] := Convolve[p[y], p1[y], y, x]

p1 succeeded. But the output of p2 only repeats the question as follows:

Convolve[UnitStep[y]/(1 + y), 
 Convolve[UnitStep[y]/(1 + y), UnitStep[y]/(1 + y), y, y], y, x]
$\endgroup$
1

2 Answers 2

1
$\begingroup$

Using partial memoization:

Clear[p];
p[0] = Function[x, 1/(x + 1)*UnitStep[x]];
p[n_Integer?Positive] := p[n] =
    Function[x, Evaluate@Convolve[p[n - 1][y], p[0][y], y, x]]

p[0][x]
(*    UnitStep[x]/(1 + x)    *)

p[1][x]
(*    ((-I \[Pi] + Log[-1 - x] + Log[1 + x]) UnitStep[x])/(2 + x)    *)

p[2][x]
(*    -(1/(3 (3 + x)))(2 \[Pi]^2 + 3 I \[Pi] Log[-2 - x] + 
      3 I \[Pi] Log[1 + x] + 3 Log[-1 - x] Log[1/(2 + x)] + 
      3 Log[1 + x] Log[1/(2 + x)] - 3 I \[Pi] Log[(1 + x)/(2 + x)] - 
      3 Log[1 + x] Log[2 + x] - 3 PolyLog[2, -1 - x] - 
      6 PolyLog[2, 1/(2 + x)] + 6 PolyLog[2, (1 + x)/(2 + x)] + 
      3 PolyLog[2, 2 + x]) UnitStep[x]                                  *)

Plot[{p[0][x], p[1][x], p[2][x]}, {x, 0, 2}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Could you please give the references for the following commands? Thank you. (1) Function; (2) p[n_Integer?Positive] (3) Evaluate@ $\endgroup$
    – Hans
    Apr 23, 2021 at 21:37
  • 1
    $\begingroup$ @Hans - In Mathematica, highlight the symbol/command that you do not understand and press F1 for help. $\endgroup$
    – Bob Hanlon
    Apr 24, 2021 at 1:59
0
$\begingroup$

There are two issues: do you have the form right, and is the integral (the convolution) solvable. Let's do the first one by picking a really simple example, like p[x]:=UnitStep[x]. You can see that your code fails. Because of the way things are defined, you need to change the variables, or they get all messed up. Note that this works:

p[x_] := UnitStep[x]
p1[x_] := Convolve[p[y], p[y], y, x]
p2[x_] := Convolve[p[z], p1[z], z, x]
p3[x_] := Convolve[p[w], p2[w], w, x]

{p[x],p1[x],p2[x],p3[x]}

Now change p[x] to your desired function... you'll see it works fine for p1[x] and p2[x]. I got bored waiting to see if p3[x] would finish. But at some point, this is going to fail because the functions are getting too hard to integrate in closed form.

$\endgroup$
4
  • $\begingroup$ I do not see any substantive difference between your code and mine. $\endgroup$
    – Hans
    Apr 23, 2021 at 20:45
  • $\begingroup$ The difference is in the arguments y,x for p1, z,x for p2 and w,x for p3. The way you have the arguments, the recursive calls get confused whereas by using new variables, it works. But anyway, Roman's solution is more general. $\endgroup$
    – bill s
    Apr 24, 2021 at 21:33
  • $\begingroup$ But z for p2 and w for p3 are local variables. They should not be used outside of the definition of p2[x_] and p3[x_], right? The choice of symbols for the local variables should be irrelevant to invocation of the function. Is it not right? $\endgroup$
    – Hans
    Apr 25, 2021 at 18:10
  • $\begingroup$ Sorry Hans, but that is incorrect. If you run your code, p2[x] does not evaluate. If you run my code, it evaluates fine. (Be sure to Clear[] the definitions in between). $\endgroup$
    – bill s
    Apr 25, 2021 at 18:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.