如何在MATLAB和WolframAlpha中计算函数与自身的卷积?

Bru*_*lza 3 matlab wolfram-mathematica wolframalpha

我正在尝试计算卷积

x(t) = 1, -1<=t<=1
x(t) = 0, outside
Run Code Online (Sandbox Code Playgroud)

与自己使用定义.

http://en.wikipedia.org/wiki/Convolution

我知道如何使用Matlab函数转换,但我想使用积分定义.我对Matlab和WolframAlpha的了解非常有限.

Amr*_*mro 8

我自己还在学习Mathematica,但这就是我想出来的......

首先我们定义分段函数(我使用维基百科页面中的示例)

f[x_] := Piecewise[{{1, -0.5 <= x <= 0.5}}, 0]
Run Code Online (Sandbox Code Playgroud)

piecewise_function

让我们绘制函数:

Plot[f[x], {x, -2, 2}, PlotStyle -> Thick, Exclusions -> None]
Run Code Online (Sandbox Code Playgroud)

function_plot

然后我们编写定义f自身卷积的函数:

g[t_] = Integrate[f[x]*f[t - x], {x, -Infinity, Infinity}]
Run Code Online (Sandbox Code Playgroud)

convolution_integral

和情节:

Plot[g[t], {t, -2, 2}, PlotStyle -> Thick]
Run Code Online (Sandbox Code Playgroud)

convolution_plot


编辑

我尝试在MATLAB/MuPad中做同样的事情,我没有那么成功:

f := x -> piecewise([x < -0.5 or x > 0.5, 0], [x >= -0.5 and x <= 0.5, 1])
Run Code Online (Sandbox Code Playgroud)

func_def

plot(f, x = -2..2)
Run Code Online (Sandbox Code Playgroud)

func_plot

但是当我尝试计算积分时,返回这个花了将近一分钟:

g := t -> int(f(x)*f(t-x), x = -infinity..infinity)
Run Code Online (Sandbox Code Playgroud)

卷积

情节(也花了太长时间)

plot(g, t = -2..2)
Run Code Online (Sandbox Code Playgroud)

convolution_plot

请注意,在MATLAB内部可以使用以下语法完成相同的操作:

evalin(symengine,'<MUPAD EXPRESSIONS HERE>')
Run Code Online (Sandbox Code Playgroud)

  • +1.为了保护您的定义反对情况下,当`t`已经定义并具有价值,可以插入`清除[T]`前`G [T] = ...`,或包裹你的定义`Block`,比如`Block [{t},g [t _] = ...]`.这不是基于`SetDelayed`与原始定义的问题(`:=`),而成为当您使用即时分配(`Set`),如正确的@acl建议更重要.我在这里考虑了一个非常相似的例子:http://www.mathprogramming-intro.org/book/node381.html (3认同)