2
$\begingroup$

Can anyone tell me why the following keeps burning my CPU without ever producing the desired plot?

f[x_, y_] := If[Sqrt[x^2 + y^2] < 1, 1, 0];  
test[t_, z_] := N[Convolve[f[x, y], f[x, y], {x, y}, {t, z}]];  
Plot3D[test[t, z], {t, -5, 5}, {z, -5, 5}];

Thanks!

$\endgroup$
  • 4
    $\begingroup$ Two reasons: 1. you re-compute the convolution for every plotted point; 2. Mathematica actually cannot do this convolution analytically anyway. (Not even if you rewrite it as f[x_, y_] := HeavisidePi[Sqrt[x^2 + y^2]/2].) $\endgroup$ – Oleksandr R. Jan 28 '16 at 14:31
  • $\begingroup$ You may try to convolve in polar coordinates. $\endgroup$ – Dr. belisarius Jan 28 '16 at 17:55
3
$\begingroup$

If you need result at some sensible time frame vs quality...

f[x_, y_] := Piecewise[{{1, Sqrt[x^2 + y^2] < 1}}]

nconv[t_, z_] := NIntegrate[f[x, y] f[x - t, y - z], 
{x, -Infinity, Infinity}, {y, -Infinity, Infinity}]

data = ParallelTable[nconv[t, z], {t, -3, 3, .2}, {z, -3, 3, .2}]; // AbsoluteTiming

{57.205376`, Null}

ListPlot3D[data, PlotRange -> All]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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