Documentation

This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

heaviside

Heaviside step function

Syntax

• ``heaviside(x)``
example

Description

example

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

Examples

Evaluate 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 Heaviside Function

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

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

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

Evaluate Heaviside Function for 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 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```

Change Value of Heaviside Function at Origin

`heaviside` assumes that the value of the Heaviside function at the origin is `1/2`.

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

Other common values for the Heaviside function at the origin are `0` and `1`. To change the value of `heaviside` at the origin, use the `'HeavisideAtOrigin'` preference of `sympref`. 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`.

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

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.

`sympref('HeavisideAtOrigin','default');`

Input Arguments

collapse all

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