|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# Heaviside Function |
| 22 | + |
| 23 | +> Evaluate the [Heaviside function][heaviside-function] for a single-precision floating-point number. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The [Heaviside function][heaviside-function] is defined as |
| 28 | + |
| 29 | +<!-- <equation class="equation" label="eq:heaviside_function" align="center" raw="H(x) = \begin{cases} 1 & \textrm{if}\ x \gt 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases}" alt="Heaviside function."> --> |
| 30 | + |
| 31 | +```math |
| 32 | +H(x) = \begin{cases} 1 & \textrm{if}\ x \gt 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases} |
| 33 | +``` |
| 34 | + |
| 35 | +<!-- <div class="equation" align="center" data-raw-text="H(x) = \begin{cases} 1 & \textrm{if}\ x \gt 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases}" data-equation="eq:heaviside_function"> |
| 36 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/heaviside/docs/img/equation_heaviside_function.svg" alt="Heaviside function."> |
| 37 | + <br> |
| 38 | +</div> --> |
| 39 | + |
| 40 | +<!-- </equation> --> |
| 41 | + |
| 42 | +and is discontinuous at `0`. Depending on the context, the [Heaviside function][heaviside-function] may be defined as a continuous function. To define the [Heaviside function][heaviside-function] such that the function has rotational symmetry, |
| 43 | + |
| 44 | +<!-- <equation class="equation" label="eq:heaviside_function_half_maximum" align="center" raw="H(x) = \begin{cases} x & \textrm{if}\ x \gt 0 \\ \frac{1}{2} & \textrm{if}\ x = 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases}" alt="Heaviside function half-maximum."> --> |
| 45 | + |
| 46 | +```math |
| 47 | +H(x) = \begin{cases} x & \textrm{if}\ x \gt 0 \\ \frac{1}{2} & \textrm{if}\ x = 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases} |
| 48 | +``` |
| 49 | + |
| 50 | +<!-- <div class="equation" align="center" data-raw-text="H(x) = \begin{cases} x & \textrm{if}\ x \gt 0 \\ \frac{1}{2} & \textrm{if}\ x = 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases}" data-equation="eq:heaviside_function_half_maximum"> |
| 51 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/heaviside/docs/img/equation_heaviside_function_half_maximum.svg" alt="Heaviside function half-maximum."> |
| 52 | + <br> |
| 53 | +</div> --> |
| 54 | + |
| 55 | +<!-- </equation> --> |
| 56 | + |
| 57 | +To define the [Heaviside function][heaviside-function] as a left-continuous function, |
| 58 | + |
| 59 | +<!-- <equation class="equation" label="eq:heaviside_function_left_continuous" align="center" raw="H(x) = \begin{cases} x & \textrm{if}\ x \gt 0 \\ 0 & \textrm{if}\ x \leq 0\end{cases}" alt="Heaviside function left-continuous."> --> |
| 60 | + |
| 61 | +```math |
| 62 | +H(x) = \begin{cases} x & \textrm{if}\ x \gt 0 \\ 0 & \textrm{if}\ x \leq 0\end{cases} |
| 63 | +``` |
| 64 | + |
| 65 | +<!-- <div class="equation" align="center" data-raw-text="H(x) = \begin{cases} x & \textrm{if}\ x \gt 0 \\ 0 & \textrm{if}\ x \leq 0\end{cases}" data-equation="eq:heaviside_function_left_continuous"> |
| 66 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/heaviside/docs/img/equation_heaviside_function_left_continuous.svg" alt="Heaviside function left-continuous."> |
| 67 | + <br> |
| 68 | +</div> --> |
| 69 | + |
| 70 | +<!-- </equation> --> |
| 71 | + |
| 72 | +To define the [Heaviside function][heaviside-function] as a right-continuous function, |
| 73 | + |
| 74 | +<!-- <equation class="equation" label="eq:heaviside_function_right_continuous" align="center" raw="H(x) = \begin{cases} x & \textrm{if}\ x \geq 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases}" alt="Heaviside function right-continuous."> --> |
| 75 | + |
| 76 | +```math |
| 77 | +H(x) = \begin{cases} x & \textrm{if}\ x \geq 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases} |
| 78 | +``` |
| 79 | + |
| 80 | +<!-- <div class="equation" align="center" data-raw-text="H(x) = \begin{cases} x & \textrm{if}\ x \geq 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases}" data-equation="eq:heaviside_function_right_continuous"> |
| 81 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/heaviside/docs/img/equation_heaviside_function_right_continuous.svg" alt="Heaviside function right-continuous."> |
| 82 | + <br> |
| 83 | +</div> --> |
| 84 | + |
| 85 | +<!-- </equation> --> |
| 86 | + |
| 87 | +</section> |
| 88 | + |
| 89 | +<!-- /.intro --> |
| 90 | + |
| 91 | +<section class="usage"> |
| 92 | + |
| 93 | +## Usage |
| 94 | + |
| 95 | +```javascript |
| 96 | +var heavisidef = require( '@stdlib/math/base/special/heavisidef' ); |
| 97 | +``` |
| 98 | + |
| 99 | +#### heavisidef( x\[, continuity] ) |
| 100 | + |
| 101 | +Evaluates the [Heaviside function][heaviside-function] for a single-precision floating-point number. |
| 102 | + |
| 103 | +```javascript |
| 104 | +var v = heavisidef( 3.14 ); |
| 105 | +// returns 1.0 |
| 106 | + |
| 107 | +v = heavisidef( -3.14 ); |
| 108 | +// returns 0.0 |
| 109 | + |
| 110 | +v = heavisidef( NaN ); |
| 111 | +// returns NaN |
| 112 | +``` |
| 113 | + |
| 114 | +The `continuity` parameter may be one of the following values: |
| 115 | + |
| 116 | +- `'half-maximum'`: if `x == 0`, the function returns `0.5`. |
| 117 | +- `'left-continuous'`: if `x == 0`, the function returns `0.0`. |
| 118 | +- `'right-continuous'`: if `x == 0`, the function returns `1.0`. |
| 119 | + |
| 120 | +By default, the function is discontinuous at `0`. |
| 121 | + |
| 122 | +```javascript |
| 123 | +var v = heavisidef( 0.0 ); |
| 124 | +// returns NaN |
| 125 | +``` |
| 126 | + |
| 127 | +To define the [Heaviside function][heaviside-function] as a continuous function, set the `continuity` parameter. |
| 128 | + |
| 129 | +```javascript |
| 130 | +var v = heavisidef( 0.0, 'half-maximum' ); |
| 131 | +// returns 0.5 |
| 132 | + |
| 133 | +v = heavisidef( 0.0, 'left-continuous' ); |
| 134 | +// returns 0.0 |
| 135 | + |
| 136 | +v = heavisidef( 0.0, 'right-continuous' ); |
| 137 | +// returns 1.0 |
| 138 | +``` |
| 139 | + |
| 140 | +</section> |
| 141 | + |
| 142 | +<!-- /.usage --> |
| 143 | + |
| 144 | +<section class="examples"> |
| 145 | + |
| 146 | +## Examples |
| 147 | + |
| 148 | +<!-- eslint no-undef: "error" --> |
| 149 | + |
| 150 | +```javascript |
| 151 | +var linspace = require( '@stdlib/array/base/linspace' ); |
| 152 | +var heavisidef = require( '@stdlib/math/base/special/heavisidef' ); |
| 153 | + |
| 154 | +var x = linspace( -10.0, 10.0, 101 ); |
| 155 | + |
| 156 | +var i; |
| 157 | +for ( i = 0; i < x.length; i++ ) { |
| 158 | + console.log( 'H(%d) = %f', x[ i ], heavisidef( x[ i ] ) ); |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +</section> |
| 163 | + |
| 164 | +<!-- /.examples --> |
| 165 | + |
| 166 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 167 | + |
| 168 | +<section class="related"> |
| 169 | + |
| 170 | +</section> |
| 171 | + |
| 172 | +<!-- /.related --> |
| 173 | + |
| 174 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 175 | + |
| 176 | +<section class="links"> |
| 177 | + |
| 178 | +[heaviside-function]: https://en.wikipedia.org/wiki/Heaviside_step_function |
| 179 | + |
| 180 | +</section> |
| 181 | + |
| 182 | +<!-- /.links --> |
0 commit comments