# Plotting a convolution fails [closed]

i'm trying to plot a graph of a convolution and a discrete convolution, using Mathematica 8

x[t_] := exp[-2*t]*(HeavisideTheta[t + 2] - HeavisideTheta[t]) +
(1 - t/2)*(HeavisideTheta[t] - HeavisideTheta[t - 2])
y[t_] := -2*DiracDelta[t + 2] +  2*(HeavisideTheta[t] - HeavisideTheta[t - 2])
c[t_] := Convolve[x[d], y[d], d, t]
Plot[c[t], {t, -4, 4}, PlotRange -> {-4, 4}, PlotStyle -> {Thickness[0.006]}]


This results in an empty graph. Can Mathematica 8 plot convolutions? Same thing happens with discrete convolution.

Any help is appreciated, thanks in advance.

• You probably want to write Exp instead of exp – Jacob Akkerboom Apr 22 '13 at 22:13
• You could have noticed that exp was undefined by seeing that it is blue. If you notice something like that you can just type it into the search bar of the documentation center. – Jacob Akkerboom Apr 22 '13 at 22:37

I'd suggest doing something like this

Clear[x, y, c, d, exp]
x[t_] := Exp[-2*t]*(HeavisideTheta[t + 2] - HeavisideTheta[t]) + (1 -
t/2)*(HeavisideTheta[t] - HeavisideTheta[t - 2])
y[t_] := -2*DiracDelta[t + 2] +
2*(HeavisideTheta[t] - HeavisideTheta[t - 2])
c[t_] := (c[t] = Convolve[x[d], y[d], d, t]);

kkkk = 4;
arr = Array[c, kkkk*8 + 1, {-4, 4}];
dom = Array[# &, kkkk*8 + 1, {-4, 4}];

ListPlot[Transpose[{dom, arr}], Joined -> True]


But note that HeavySideTheta is not defined.

Remark about the definition of c

It takes a little while to calculate c. Therefore I used the idiom c[t_]:=c[t]=expr which stores values you have already calculated. Not really necessary as I also store your values in an array, but oh well.

Better alternative

You can use the algebraic capabilities to simplify the definition of c first. Then it will no longer take long to calculate values of c. Set

Clear[x, y, c, d, c2]
x[t_] := Exp[-2*t]*(HeavisideTheta[t + 2] - HeavisideTheta[t]) + (1 -
t/2)*(HeavisideTheta[t] - HeavisideTheta[t - 2])
y[t_] := -2*DiracDelta[t + 2] +
2*(HeavisideTheta[t] - HeavisideTheta[t - 2])

(*takes a while*)
c2[t_] := Evaluate[FullSimplify[Convolve[x[d], y[d], d, t]]]


Then you can simply do

Plot[c2[t], {t, -4, 4}, PlotRange -> {{-4, 4}, Automatic},
PlotStyle -> {Thickness[0.006]}]


• @Nicholas You're welcome. It depends on the argument of c how long it takes. To calculate 9 values of c in the range {-4,4} took about 30 seconds I guess. You can use Clear[c];AbsoluteTiming[Array[c, kkkk*8 + 1, {-4, 4}]][] if you want to see how long it took. It also takes less than a minute to complete the (definition using) FullSimplify. – Jacob Akkerboom Apr 22 '13 at 22:51