README.md (2620B)
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 # Absolute Value 22 23 > Compute an [absolute value][absolute-value] of a complex number. 24 25 <section class="intro"> 26 27 The [absolute value][absolute-value] of a complex number is defined as 28 29 <!-- <equation class="equation" label="eq:absolute_value_complex" align="center" raw="|a + bi| = \sqrt{a^2 + b^2}" alt="Absolute value"> --> 30 31 <div class="equation" align="center" data-raw-text="|a + bi| = \sqrt{a^2 + b^2}" data-equation="eq:absolute_value_complex"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@d4edb68b52a6c646be5683023c5a24890300727f/lib/node_modules/@stdlib/math/base/special/cabs/docs/img/equation_absolute_value_complex.svg" alt="Absolute value"> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 which corresponds to the length of a vector from the origin to a complex value plotted in the complex plane. 39 40 </section> 41 42 <!-- /.intro --> 43 44 <section class="usage"> 45 46 ## Usage 47 48 ```javascript 49 var cabs = require( '@stdlib/math/base/special/cabs' ); 50 ``` 51 52 #### cabs( re, im ) 53 54 Computes an [absolute value][absolute-value] of a `complex` number comprised of a **real** component `re` and an **imaginary** component `im`. 55 56 ```javascript 57 var y = cabs( 5.0, 3.0 ); 58 // returns ~5.83 59 ``` 60 61 </section> 62 63 <!-- /.usage --> 64 65 <section class="examples"> 66 67 ## Examples 68 69 <!-- eslint no-undef: "error" --> 70 71 ```javascript 72 var Complex128 = require( '@stdlib/complex/float64' ); 73 var randu = require( '@stdlib/random/base/randu' ); 74 var round = require( '@stdlib/math/base/special/round' ); 75 var real = require( '@stdlib/complex/real' ); 76 var imag = require( '@stdlib/complex/imag' ); 77 var cabs = require( '@stdlib/math/base/special/cabs' ); 78 79 var re; 80 var im; 81 var z; 82 var i; 83 84 for ( i = 0; i < 100; i++ ) { 85 re = round( randu()*100.0 ) - 50.0; 86 im = round( randu()*100.0 ) - 50.0; 87 z = new Complex128( re, im ); 88 console.log( 'cabs(%s) = %d', z.toString(), cabs( real(z), imag(z) ) ); 89 } 90 ``` 91 92 </section> 93 94 <!-- /.examples --> 95 96 <section class="links"> 97 98 [absolute-value]: https://en.wikipedia.org/wiki/Absolute_value 99 100 </section> 101 102 <!-- /.links -->