time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (5687B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 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].
     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 <div class="equation" align="center" data-raw-text="H(x) = \begin{cases} 1 &amp; \textrm{if}\ x \gt 0 \\ 0 &amp; \textrm{if}\ x \lt 0\end{cases}" data-equation="eq:heaviside_function">
     32     <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.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 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,
     39 
     40 <!-- <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."> -->
     41 
     42 <div class="equation" align="center" data-raw-text="H(x) = \begin{cases} x &amp; \textrm{if}\ x \gt 0 \\ \frac{1}{2} &amp; \textrm{if}\ x = 0 \\ 0 &amp; \textrm{if}\ x \lt 0\end{cases}" data-equation="eq:heaviside_function_half_maximum">
     43     <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.">
     44     <br>
     45 </div>
     46 
     47 <!-- </equation> -->
     48 
     49 To define the [Heaviside function][heaviside-function] as a left-continuous function,
     50 
     51 <!-- <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."> -->
     52 
     53 <div class="equation" align="center" data-raw-text="H(x) = \begin{cases} x &amp; \textrm{if}\ x \gt 0 \\ 0 &amp; \textrm{if}\ x \leq 0\end{cases}" data-equation="eq:heaviside_function_left_continuous">
     54     <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.">
     55     <br>
     56 </div>
     57 
     58 <!-- </equation> -->
     59 
     60 To define the [Heaviside function][heaviside-function] as a right-continuous function,
     61 
     62 <!-- <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."> -->
     63 
     64 <div class="equation" align="center" data-raw-text="H(x) = \begin{cases} x &amp; \textrm{if}\ x \geq 0 \\ 0 &amp; \textrm{if}\ x \lt 0\end{cases}" data-equation="eq:heaviside_function_right_continuous">
     65     <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.">
     66     <br>
     67 </div>
     68 
     69 <!-- </equation> -->
     70 
     71 </section>
     72 
     73 <!-- /.intro -->
     74 
     75 <section class="usage">
     76 
     77 ## Usage
     78 
     79 ```javascript
     80 var heaviside = require( '@stdlib/math/base/special/heaviside' );
     81 ```
     82 
     83 #### heaviside( x\[, continuity] )
     84 
     85 Evaluates the [Heaviside function][heaviside-function].
     86 
     87 ```javascript
     88 var v = heaviside( 3.14 );
     89 // returns 1.0
     90 
     91 v = heaviside( -3.14 );
     92 // returns 0.0
     93 
     94 v = heaviside( NaN );
     95 // returns NaN
     96 ```
     97 
     98 The `continuity` parameter may be one of the following values:
     99 
    100 -   `'half-maximum'`: if `x == 0`, the function returns `0.5`.
    101 -   `'left-continuous'`: if `x == 0`, the function returns `0.0`.
    102 -   `'right-continuous'`: if `x == 0`, the function returns `1.0`.
    103 
    104 By default, the function is discontinuous at `0`.
    105 
    106 ```javascript
    107 var v = heaviside( 0.0 );
    108 // returns NaN
    109 ```
    110 
    111 To define the [Heaviside function][heaviside-function] as a continuous function, set the `continuity` parameter.
    112 
    113 ```javascript
    114 var v = heaviside( 0.0, 'half-maximum' );
    115 // returns 0.5
    116 
    117 v = heaviside( 0.0, 'left-continuous' );
    118 // returns 0.0
    119 
    120 v = heaviside( 0.0, 'right-continuous' );
    121 // returns 1.0
    122 ```
    123 
    124 </section>
    125 
    126 <!-- /.usage -->
    127 
    128 <section class="examples">
    129 
    130 ## Examples
    131 
    132 <!-- eslint no-undef: "error" -->
    133 
    134 ```javascript
    135 var linspace = require( '@stdlib/array/linspace' );
    136 var heaviside = require( '@stdlib/math/base/special/heaviside' );
    137 
    138 var x = linspace( -10.0, 10.0, 101 );
    139 var i;
    140 
    141 for ( i = 0; i < x.length; i++ ) {
    142     console.log( 'H(%d) = %d', x[ i ], heaviside( x[ i ] ) );
    143 }
    144 ```
    145 
    146 </section>
    147 
    148 <!-- /.examples -->
    149 
    150 <section class="links">
    151 
    152 [heaviside-function]: https://en.wikipedia.org/wiki/Heaviside_step_function
    153 
    154 </section>
    155 
    156 <!-- /.links -->