Accelerating the pace of engineering and science

# Documentation Center

• Trials
• Product Updates

# heaviside

Heaviside step function

## Description

example

heaviside(x) returns the value 0 for x < 0, 1 for x > 0, and 1/2 for x = 0.

## Examples

### Evaluate the Heaviside Function for Numeric and Symbolic Arguments

Depending on the argument value, heaviside returns one of these values: 0, 1, or 1/2. If the argument is a floating-point number (not a symbolic object), then heaviside returns floating-point results.

For x < 0, the function heaviside(x) returns 0:

`heaviside(sym(-3))`
```ans =
0```

For x > 0, the function heaviside(x) returns 1:

`heaviside(sym(3))`
```ans =
1```

For x = 0, the function heaviside(x) returns 1/2:

`heaviside(sym(0))`
```ans =
1/2```

For numeric x = 0, the function heaviside(x) returns the numeric result:

`heaviside(0)`
```ans =
0.5000```

### Use Assumptions on Variables

heaviside takes into account assumptions on variables.

```syms x
assume(x < 0)
heaviside(x)```
```ans =
0```

For further computations, clear the assumptions:

`syms x clear`

### Plot the Heaviside Function

Plot the Heaviside step function for x and x - 1 .

```syms x
ezplot(heaviside(x), [-2, 2])
```

```ezplot(heaviside(x - 1), [-2, 2])
```

### Evaluate the Heaviside Function for a Symbolic Matrix

Call heaviside for this symbolic matrix. When the input argument is a matrix, heaviside computes the Heaviside function for each element.

```syms x
heaviside(sym([-1 0; 1/2 x]))```
```ans =
[ 0,          1/2]
[ 1, heaviside(x)]```

### Differentiate and Integrate Expressions Involving the Heaviside Function

Compute derivatives and integrals of expressions involving the Heaviside function.

Find the first derivative of the Heaviside function. The first derivative of the Heaviside function is the Dirac delta function.

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

Find the integral of the expression involving the Heaviside function:

```syms x
int(exp(-x)*heaviside(x), x, -Inf, Inf)```
```ans =
1```

## Input Arguments

expand all

### x — Inputsymbolic number | symbolic variable | symbolic expression | symbolic function | symbolic vector | symbolic matrix

Input, specified as a symbolic number, variable, expression, function, vector, or matrix.

## See Also

Was this topic helpful?