H = heaviside(x)
evaluates the Heaviside step function (also known as the unit step function) at
x. The Heaviside function is a discontinuous function that
returns 0 for x < 0, 1/2
for x = 0, and 1 for x >
0.
The heaviside function returns 0, 1/2, or 1 depending on the argument value. If the argument is a floating-point number (not a symbolic object), then heaviside returns floating-point results.
Evaluate the Heaviside step function for a symbolic input sym(-3). The function heaviside(x) returns 0 for x < 0.
H = heaviside(sym(-3))
H =
Evaluate the Heaviside step function for a symbolic input sym(3). The function heaviside(x) returns 1 for x > 0.
H = heaviside(sym(3))
H =
Evaluate the Heaviside step function for a symbolic input sym(0). The function heaviside(x) returns 1/2 for x = 0.
H = heaviside(sym(0))
H =
For a numeric input x = 0, the function heaviside(x) returns floating-point results.
Evaluate the Heaviside function for a symbolic matrix. When the input argument is a matrix, heaviside computes the Heaviside function for each element.
syms x
H = heaviside(sym([-1 0; 1/2 x]))
H =
Differentiate and Integrate Expressions Involving Heaviside Function
The default value of the Heaviside function at the origin is 1/2.
H = heaviside(sym(0))
H =
Other common values for the Heaviside function at the origin are 0 and 1. To change the value of heaviside at the origin, use sympref to set the value of the 'HeavisideAtOrigin' preference. Store the previous parameter value returned by sympref, so that you can restore it later.
oldparam = sympref('HeavisideAtOrigin',1);
Check the new value of heaviside at 0.
H = heaviside(sym(0))
H =
The preferences set by sympref persist throughout your current and future MATLAB® sessions. To restore the previous value of heaviside at the origin, use the value stored in oldparam.
sympref('HeavisideAtOrigin',oldparam);
Alternatively, you can restore the default value of 'HeavisideAtOrigin' by using the 'default' setting.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.