Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am still learning Mathematica myself, but here is what I came up with..</p> <p>First we define the piecewise function (I am using the example from the Wikipedia page)</p> <pre><code>f[x_] := Piecewise[{{1, -0.5 &lt;= x &lt;= 0.5}}, 0] </code></pre> <p><img src="https://i.stack.imgur.com/d0TPs.png" alt="piecewise_function"></p> <p>Lets plot the function:</p> <pre><code>Plot[f[x], {x, -2, 2}, PlotStyle -&gt; Thick, Exclusions -&gt; None] </code></pre> <p><img src="https://i.stack.imgur.com/tTUxo.png" alt="function_plot"></p> <p>Then we write the function that defines the convolution of <code>f</code> with itself:</p> <pre><code>g[t_] = Integrate[f[x]*f[t - x], {x, -Infinity, Infinity}] </code></pre> <p><img src="https://i.stack.imgur.com/eFxuV.png" alt="convolution_integral"></p> <p>and the plot:</p> <pre><code>Plot[g[t], {t, -2, 2}, PlotStyle -&gt; Thick] </code></pre> <p><img src="https://i.stack.imgur.com/Xv8yY.png" alt="convolution_plot"></p> <hr> <h3>EDIT</h3> <p>I tried to do the same in MATLAB/MuPad, I wasn't as successful:</p> <pre><code>f := x -&gt; piecewise([x &lt; -0.5 or x &gt; 0.5, 0], [x &gt;= -0.5 and x &lt;= 0.5, 1]) </code></pre> <p><img src="https://i.stack.imgur.com/whfpS.png" alt="func_def"></p> <pre><code>plot(f, x = -2..2) </code></pre> <p><img src="https://i.stack.imgur.com/uB84D.png" alt="func_plot"></p> <p>However when I try to compute the integral, it took almost a minute to return this:</p> <pre><code>g := t -&gt; int(f(x)*f(t-x), x = -infinity..infinity) </code></pre> <p><img src="https://i.stack.imgur.com/zeZQ7.png" alt="convolution"></p> <p>the plot (also took too long)</p> <pre><code>plot(g, t = -2..2) </code></pre> <p><img src="https://i.stack.imgur.com/pnY90.png" alt="convolution_plot"></p> <p>Note the same could have been done from inside MATLAB with the syntax:</p> <pre><code>evalin(symengine,'&lt;MUPAD EXPRESSIONS HERE&gt;') </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload