Contact Us
How To Buy
Log In
Products
Solutions
Academia
Support
Community
Events
Company
Search MATLAB Documentation
Documentation
Documentation
Toggle navigation
Trial Software
Product Updates
All Products
Symbolic Math Toolbox
Mathematics
Mathematical Functions
Special Functions
Dirac and Heaviside Functions
kroneckerDelta
ON THIS PAGE
Syntax
Description
Examples
o Compare Two Symbolic Variables
o Compare Symbolic Variable with Zero
o Compare Vector of Numbers with Symbolic Variable
o Compare Two Matrices
o Use kroneckerDelta in Inputs to Other Functions
o Filter Response to Kronecker Delta Input
Input Arguments
More About
See Also
kroneckerDelta
Kronecker delta function
collapse all in page
Syntax
kroneckerDelta(m)
example
kroneckerDelta(m,n)
example
Description
example
kroneckerDelta(m) returns 1 if m == 0 and 0 if m ~= 0.
example
kroneckerDelta(m,n) returns 1 if m == n and 0 if m ~= n.
Examples
Compare Two Symbolic Variables
Set symbolic variable m equal to symbolic variable n and test their equality
using kroneckerDelta.
syms m n
m = n;
kroneckerDelta(m, n)
ans =
1
kroneckerDelta returns 1 indicating that the inputs are equal.
Compare symbolic variables p and q.
syms p q
kroneckerDelta(p, q)
ans =
kroneckerDelta(p - q, 0)
kroneckerDelta cannot decide if p == q and returns the function call with the undecidable
input. Note that kroneckerDelta(p, q) is equal to kroneckerDelta(p - q, 0).
To force a logical result for undecidable inputs, use isAlways. The isAlways function issues
a warning and returns logical 0 (false) for undecidable inputs. Set the Unknown option
to false to suppress the warning.
isAlways(kroneckerDelta(p, q), 'Unknown', 'false')
ans =
0
Compare Symbolic Variable with Zero
Set symbolic variable m to 0 and test m for equality with 0. The kroneckerDelta function errors
because it does not accept numeric inputs of type double.
m = 0;
kroneckerDelta(m)
Undefined function 'kroneckerDelta' for input arguments of type 'double'.
Use sym to convert 0 to a symbolic object before assigning it to m. This is
because kroneckerDelta only accepts symbolic inputs.
syms m
m = sym(0);
kroneckerDelta(m)
ans =
1
kroneckerDelta returns 1 indicating that m is equal to 0. Note that kroneckerDelta(m) is equal
to kroneckerDelta(m, 0).
Compare Vector of Numbers with Symbolic Variable
Compare a vector of numbers [1 2 3 4] with symbolic variable m. Set m to 3.
V = 1:4
syms m
m = sym(3)
sol = kroneckerDelta(V, m)
V =
1 2 3 4
m =
3
sol =
[ 0, 0, 1, 0]
kroneckerDelta acts on V element-wise to return a vector, sol, which is the same size as V.
The third element of sol is 1 indicating that the third element of V equals m.
Compare Two Matrices
Compare matrices A and B.
Declare matrices A and B.
syms m
A = [m m+1 m+2;m-2 m-1 m]
B = [m m+3 m+2;m-1 m-1 m+1]
A =
[ m, m + 1, m + 2]
[ m - 2, m - 1, m]
B =
[ m, m + 3, m + 2]
[ m - 1, m - 1, m + 1]
Compare A and B using kroneckerDelta.
sol = kroneckerDelta(A, B)
sol =
[ 1, 0, 1]
[ 0, 1, 0]
kroneckerDelta acts on A and B element-wise to return the matrix sol which is the same size
as A and B. The elements of sol that are 1 indicate that the corresponding elements
of A and B are equal. The elements of sol that are 0 indicate that the corresponding
elements of A and B are not equal.
Use kroneckerDelta in Inputs to Other Functions
kroneckerDelta appears in the output of iztrans.
syms z n
sol = iztrans(1/(z-1), z, n)
sol =
1 - kroneckerDelta(n, 0)
Use this output as input to ztrans to return the initial input expression.
ztrans(sol, n, z)
ans =
z/(z - 1) - 1
Filter Response to Kronecker Delta Input
Use filter to find the response of a filter when the input is the Kronecker Delta function.
Convert k to a symbolic vector using sym because kroneckerDelta only accepts symbolic
inputs, and convert it back to double using double. Provide arbitrary filter
coefficients a and b for simplicity.
b = [0 1 1];
a = [1 -0.5 0.3];
k = -20:20;
x = double(kroneckerDelta(sym(k)));
y = filter(b,a,x);
plot(k,y)
Input Arguments
collapse all
m Inputnumber | vector | matrix | multidimensional array | symbolic number | symbolic vector | symbolic matrix |
symbolic function | symbolic multidimensional array
Input, specified as a number, vector, matrix, multidimensional array, or a symbolic number,
vector, matrix, function, or multidimensional array. At least one of the inputs, m or n, must be
symbolic.
n Inputnumber | vector | matrix | multidimensional array | symbolic number | symbolic vector | symbolic matrix |
symbolic function | symbolic multidimensional array
Input, specified as a number, vector, matrix, multidimensional array, or a symbolic number,
vector, matrix, function, or multidimensional array. At least one of the inputs, m or n, must be
symbolic.
More About
expand all
Kronecker Delta Function
The Kronecker delta function is defined as
{
( )
m,n = 01if mif mn=n
Tips
When m or n is NaN, the kroneckerDelta function
returns NaN.
See Also
iztrans | ztrans
Introduced in R2014b
Was this topic helpful?
Symbolic Math Toolbox Documentation
Getting Started
Examples
Functions and Other Reference
Release Notes
PDF Documentation
Other Documentation
MATLAB
Statistics and Machine Learning Toolbox
Optimization Toolbox
Control System Toolbox
Signal Processing Toolbox
All Products
Support
MATLAB Answers
Installation Help
Bug Reports
Product Requirements
Software Downloads
Try MATLAB, Simulink, and Other Products
Get trial now
United States
Patents
Trademarks
Privacy Policy
Preventing Piracy
1994-2016 The MathWorks, Inc.
Join the conversation