Deriving dirac delta function using Matlab symbolic toolbox

前端 未结 2 1798
半阙折子戏
半阙折子戏 2020-12-21 13:13

i\'m new in matlab. I didn\'t understand how to derive a dirac delta function and then shift it using symbolic toolbox.

syms t
x = dirac(t)
<
2条回答
  •  眼角桃花
    2020-12-21 13:58

    As others have noted, the Dirac delta function is not a true function, but a generalized function. The help for dirac indicates this:

    dirac(X) is not a function in the strict sense, but rather a
    distribution with int(dirac(x-a)*f(x),-inf,inf) = f(a) and
    diff(heaviside(x),x) = dirac(x).

    Strictly speaking, it's impossible for Matlab to plot the Dirac delta function in the normal way because part of it extends to infinity. However, there are numerous workarounds if you want a visualization. A simple one is to use the stem plot function and the > operator to convert the one Inf value to something finite. This produces a unit impulse function (or Kronecker delta):

    t = -10:10;
    x = dirac(t) > 0;
    stem(t,x)
    

    If t and x already exist as symbolic variables/expressions rather than numeric ones you can use subs:

    syms t
    x = dirac(t);
    t2 = -10:10;
    x2 = subs(x,t,t2)>0;
    stem(t2, x2)
    

    You can write your own plot routine if you want something that looks different. Using ezplot is not likely to work as it doesn't offer as much control.

提交回复
热议问题