dirac

d = dirac( x ) represents the Dirac delta function of x .

d = dirac( n , x ) represents the n th derivative of the Dirac delta function at x .

Examples

Handle Expressions Involving Dirac and Heaviside Functions

Compute derivatives and integrals of expressions involving the Dirac delta and Heaviside functions.

Find the first and second derivatives of the Heaviside function. The result is the Dirac delta function and its first derivative.

syms x diff(heaviside(x), x) diff(heaviside(x), x, x)
ans = dirac(x) ans = dirac(1, x)

Find the indefinite integral of the Dirac delta function. The results returned by int do not include integration constants.

int(dirac(x), x)
ans = sign(x)/2

Find the integral of the sine function involving the Dirac delta function.

syms a int(dirac(x - a)*sin(x), x, -Inf, Inf)
ans = sin(a)

Use Assumptions on Variables

dirac takes into account assumptions on variables.

syms x real assumeAlso(x ~= 0) dirac(x)
ans = 0

For further computations, clear the assumptions on x by recreating it using syms .

syms x

Evaluate Dirac Delta Function for Symbolic Matrix

Compute the Dirac delta function of x and its first three derivatives.

Use a vector n = [0,1,2,3] to specify the order of derivatives. The dirac function expands the scalar into a vector of the same size as n and computes the result.

syms x n = [0,1,2,3]; d = dirac(n,x)
d = [ dirac(x), dirac(1, x), dirac(2, x), dirac(3, x)]

Substitute x with 0 .

subs(d,x,0)
ans = [ Inf, -Inf, Inf, -Inf]

Plot Dirac Delta Function

You can use fplot to plot the Dirac delta function over the default interval [-5 5] . However, dirac(x) returns Inf at x equal to 0 , and fplot does not plot the infinity.

Declare a symbolic variable x and plot the symbolic expression dirac(x) by using fplot .

syms x fplot(dirac(x))

Plot <a href=of the Dirac delta function where the infinity at x equal to 0 is omitted." width="560" height="420" />

To handle the infinity at x equal to 0 , use numeric values instead of symbolic values. Set the Inf value to 1 and plot the Dirac delta function by using stem .

x = -1:0.1:1; y = dirac(x); idx = y == Inf; % find Inf y(idx) = 1; % set Inf to finite value stem(x,y)

Plot <a href=of the Dirac delta function with value 1 at x equal to 0." width="560" height="420" />

Input Arguments

x — Input
number | symbolic number | symbolic variable | symbolic expression | symbolic function | vector | matrix | multidimensional array

Input, specified as a number, symbolic number, variable, expression, or function, representing a real number. This input can also be a vector, matrix, or multidimensional array of numbers, symbolic numbers, variables, expressions, or functions.

n — Order of derivative
nonnegative number | symbolic variable | symbolic expression | symbolic function | vector | matrix | multidimensional array

Order of derivative, specified as a nonnegative number, or symbolic variable, expression, or function representing a nonnegative number. This input can also be a vector, matrix, or multidimensional array of nonnegative numbers, symbolic numbers, variables, expressions, or functions.

More About

Dirac Delta Function

The Dirac delta function, δ(x) , has the value 0 for all x ≠ 0 , and ∞ for x = 0 . The Dirac delta function satisfies the identity

This is a heuristic definition of the Dirac delta function. A rigorous definition of the Dirac delta function requires the theory of distributions or measure theory.

For any smooth function f and a real number a, the Dirac delta function has the property

∫ − ∞ ∞ δ ( x − a ) f ( x ) = f ( a ) .

Tips

Version History

Introduced before R2006a