Deriving dirac delta function using Matlab symbolic toolbox

前端 未结 2 1783
半阙折子戏
半阙折子戏 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.

    0 讨论(0)
  • 2020-12-21 13:59

    First, I've not met ezplot before; I had to read up on it. For things that are functionals like your x, it's handy, but you still have to realize it's exactly giving you what it promises: A plot.

    If you had the job of plotting the dirac delta function, how would you go about doing it correctly? You can't. You must find a convention of annotating your plot with the info that there is a single, isolated, infinite point in your plot.

    Plotting something with a line plot hence is unsuitable for anything but smooth functions (that's a well-defined term). Dirac Delta definitely isn't amongst the class of functions that are smooth. You would typically use a vertical line or something to denote the point where your functional is not 0.

    0 讨论(0)
提交回复
热议问题