Advertisement
Matthen

Convolutions to get Gaussian

May 9th, 2012
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. xmax = 4;
  2. ConvolveAnim[f_, g_, c_, t_] :=
  3. Module[{\[Tau] = 1.5 xmax - 2.5 xmax t}, Show[
  4.  
  5. Plot[f[x], {x, -xmax, xmax}, PlotRange -> {0, 3}, Axes -> None,
  6. ImageSize -> 300]
  7. ,
  8. Plot[g[x + \[Tau]], {x, -xmax, xmax}],
  9. Plot[c[x], {x, -xmax, -\[Tau]},
  10. PlotStyle -> Directive[Thick, Black]],
  11. RegionPlot[
  12. 0 <= y <= g[x + \[Tau]] f[x], {x, -xmax, xmax}, {y, 0, 3},
  13. PlotPoints -> 50, PlotStyle -> RGBColor[0.8, 0.6, 0.65]]
  14. ]];
  15. conv[1, x_] := f[x];
  16. conv[n_, x_] :=
  17. conv[n, x] = (Convolve[f[ttt], conv[n - 1, ttt], ttt, xt]) /. {xt ->
  18. x};
  19. convs = Table[conv[i, x], {i, 5}];
  20. convs = convs/(convs /. {x -> 0});
  21. anim[n_, t_] :=
  22. ConvolveAnim[(convs[[n]] /. {x -> #}) &,
  23. f, (convs[[n + 1]] /. {x -> #}) &, t];
  24. animall[t_] := anim[1 + Floor[t], t - Floor[t]];
  25.  
  26. frames = Table[animall[t], {t, 0, 3.99, 0.0399}];
  27.  
  28. Export["convolve.gif", frames];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement