|
| 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 | +# Dirac Delta |
| 22 | + |
| 23 | +> Evaluate the [Dirac delta function][dirac-delta-function] in single-precision floating-point format. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The [Dirac delta function][dirac-delta-function] may be loosely defined as |
| 28 | + |
| 29 | +<!-- <equation class="equation" label="eq:dirac_delta" align="center" raw="\delta = \begin{cases} \infty & \textrm{if}\ x = 0 \\ 0 & \textrm{if}\ x \neq 0\end{cases}" alt="Dirac delta function."> --> |
| 30 | + |
| 31 | +```math |
| 32 | +\delta = \begin{cases} \infty & \textrm{if}\ x = 0 \\ 0 & \textrm{if}\ x \neq 0\end{cases} |
| 33 | +``` |
| 34 | + |
| 35 | +<!-- <div class="equation" align="center" data-raw-text="\delta = \begin{cases} \infty & \textrm{if}\ x = 0 \\ 0 & \textrm{if}\ x \neq 0\end{cases}" data-equation="eq:dirac_delta"> |
| 36 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/dirac-delta/docs/img/equation_dirac_delta.svg" alt="Dirac delta function."> |
| 37 | + <br> |
| 38 | +</div> --> |
| 39 | + |
| 40 | +<!-- </equation> --> |
| 41 | + |
| 42 | +and is constrained to satisfy the identity |
| 43 | + |
| 44 | +<!-- <equation class="equation" label="eq:dirac_delta_integral" align="center" raw="\int^{+\infty}_{-\infty} \delta(x)\ dx = 1" alt="Dirac delta function integral."> --> |
| 45 | + |
| 46 | +```math |
| 47 | +\int^{+\infty}_{-\infty} \delta(x)\ dx = 1 |
| 48 | +``` |
| 49 | + |
| 50 | +<!-- <div class="equation" align="center" data-raw-text="\int^{+\infty}_{-\infty} \delta(x)\ dx = 1" data-equation="eq:dirac_delta_integral"> |
| 51 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/dirac-delta/docs/img/equation_dirac_delta_integral.svg" alt="Dirac delta function integral."> |
| 52 | + <br> |
| 53 | +</div> --> |
| 54 | + |
| 55 | +<!-- </equation> --> |
| 56 | + |
| 57 | +Note that the [Dirac delta function][dirac-delta-function] is **not** a function in the traditional sense, as any real-valued function which is zero everywhere except at a single point, must have an integral equal to `0`. |
| 58 | + |
| 59 | +</section> |
| 60 | + |
| 61 | +<!-- /.intro --> |
| 62 | + |
| 63 | +<section class="usage"> |
| 64 | + |
| 65 | +## Usage |
| 66 | + |
| 67 | +```javascript |
| 68 | +var diracDeltaf = require( '@stdlib/math/base/special/dirac-deltaf' ); |
| 69 | +``` |
| 70 | + |
| 71 | +#### diracDeltaf( x ) |
| 72 | + |
| 73 | +Evaluates the [Dirac delta function][dirac-delta-function] in single-precision floating-point format. |
| 74 | + |
| 75 | +```javascript |
| 76 | +var v = diracDeltaf( 0.0 ); |
| 77 | +// returns Infinity |
| 78 | + |
| 79 | +v = diracDeltaf( 3.14 ); |
| 80 | +// returns 0.0 |
| 81 | + |
| 82 | +v = diracDeltaf( NaN ); |
| 83 | +// returns NaN |
| 84 | +``` |
| 85 | + |
| 86 | +</section> |
| 87 | + |
| 88 | +<!-- /.usage --> |
| 89 | + |
| 90 | +<section class="examples"> |
| 91 | + |
| 92 | +## Examples |
| 93 | + |
| 94 | +<!-- eslint no-undef: "error" --> |
| 95 | + |
| 96 | +```javascript |
| 97 | +var linspace = require( '@stdlib/array/base/linspace' ); |
| 98 | +var diracDeltaf = require( '@stdlib/math/base/special/dirac-deltaf' ); |
| 99 | + |
| 100 | +var x = linspace( -1.0, 1.0, 101 ); |
| 101 | + |
| 102 | +var i; |
| 103 | +for ( i = 0; i < x.length; i++ ) { |
| 104 | + console.log( 'dirac(%d) = %d', x[ i ], diracDeltaf( x[ i ] ) ); |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +</section> |
| 109 | + |
| 110 | +<!-- /.examples --> |
| 111 | + |
| 112 | +<!-- C interface documentation. --> |
| 113 | + |
| 114 | +* * * |
| 115 | + |
| 116 | +<section class="c"> |
| 117 | + |
| 118 | +## C APIs |
| 119 | + |
| 120 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 121 | + |
| 122 | +<section class="intro"> |
| 123 | + |
| 124 | +</section> |
| 125 | + |
| 126 | +<!-- /.intro --> |
| 127 | + |
| 128 | +<!-- C usage documentation. --> |
| 129 | + |
| 130 | +<section class="usage"> |
| 131 | + |
| 132 | +### Usage |
| 133 | + |
| 134 | +```c |
| 135 | +#include "stdlib/math/base/special/dirac_deltaf.h" |
| 136 | +``` |
| 137 | + |
| 138 | +#### stdlib_base_dirac_deltaf( x ) |
| 139 | + |
| 140 | +Evaluates the [Dirac delta function][dirac-delta-function] in single-precision floating-point format. |
| 141 | + |
| 142 | +```c |
| 143 | +float x = stdlib_base_dirac_deltaf( 0.0f ); |
| 144 | +// returns Infinity |
| 145 | + |
| 146 | +x = stdlib_base_dirac_deltaf( 3.14f ); |
| 147 | +// returns 0.0f |
| 148 | +``` |
| 149 | + |
| 150 | +The function accepts the following arguments: |
| 151 | + |
| 152 | +- **x**: `[in] float` input value. |
| 153 | + |
| 154 | +```c |
| 155 | +float stdlib_base_dirac_delta( const float x ); |
| 156 | +``` |
| 157 | +
|
| 158 | +</section> |
| 159 | +
|
| 160 | +<!-- /.usage --> |
| 161 | +
|
| 162 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 163 | +
|
| 164 | +<section class="notes"> |
| 165 | +
|
| 166 | +</section> |
| 167 | +
|
| 168 | +<!-- /.notes --> |
| 169 | +
|
| 170 | +<!-- C API usage examples. --> |
| 171 | +
|
| 172 | +<section class="examples"> |
| 173 | +
|
| 174 | +### Examples |
| 175 | +
|
| 176 | +```c |
| 177 | +#include "stdlib/math/base/special/dirac_deltaf.h" |
| 178 | +#include <stdlib.h> |
| 179 | +#include <stdio.h> |
| 180 | +
|
| 181 | +int main( void ) { |
| 182 | + const float x[] = { -1.0f, -0.5f, 0.0f, 0.5f, 1.0f, 3.14f, 2.0f }; |
| 183 | +
|
| 184 | + float v; |
| 185 | + int i; |
| 186 | + for ( i = 0; i < 7; i++ ) { |
| 187 | + v = stdlib_base_dirac_deltaf( x[ i ] ); |
| 188 | + printf( "dirac(%f) = %f\n", x[ i ], v ); |
| 189 | + } |
| 190 | +} |
| 191 | +``` |
| 192 | + |
| 193 | +</section> |
| 194 | + |
| 195 | +<!-- /.examples --> |
| 196 | + |
| 197 | +</section> |
| 198 | + |
| 199 | +<!-- /.c --> |
| 200 | + |
| 201 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 202 | + |
| 203 | +<section class="related"> |
| 204 | + |
| 205 | +</section> |
| 206 | + |
| 207 | +<!-- /.related --> |
| 208 | + |
| 209 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 210 | + |
| 211 | +<section class="links"> |
| 212 | + |
| 213 | +[dirac-delta-function]: https://en.wikipedia.org/wiki/Dirac_delta_function |
| 214 | + |
| 215 | +<!-- <related-links> --> |
| 216 | + |
| 217 | +<!-- </related-links> --> |
| 218 | + |
| 219 | +</section> |
| 220 | + |
| 221 | +<!-- /.links --> |
0 commit comments