README.md (4035B)
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 # inv 22 23 > Compute the inverse of a complex number. 24 25 <section class="intro"> 26 27 The inverse (or reciprocal) of a non-zero complex number `z = a + bi` is defined as 28 29 <!-- <equation class="equation" label="eq:complex_inverse" align="center" raw="{\frac {1}{z}}=\frac{\bar{z}}{z{\bar{z}}} = \frac{a}{a^{2}+b^{2}} - \frac{b}{a^2+b^2}i." alt="Complex Inverse" > --> 30 31 <div class="equation" align="center" data-raw-text="{\frac {1}{z}}=\frac{\bar{z}}{z{\bar{z}}} = \frac{a}{a^{2}+b^{2}} - \frac{b}{a^2+b^2}i." data-equation="eq:complex_inverse"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@026bc0ee34051ddb44f3222f620bc7a300b9799e/lib/node_modules/@stdlib/math/base/special/cinv/docs/img/equation_complex_inverse.svg" alt="Complex Inverse"> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 </section> 39 40 <!-- /.intro --> 41 42 <section class="usage"> 43 44 ## Usage 45 46 ```javascript 47 var cinv = require( '@stdlib/math/base/special/cinv' ); 48 ``` 49 50 #### cinv( \[out,] re1, im1 ) 51 52 Computes the inverse of a `complex` number comprised of a **real** component `re` and an **imaginary** component `im`. 53 54 ```javascript 55 var v = cinv( 2.0, 4.0 ); 56 // returns [ 0.1, -0.2 ] 57 ``` 58 59 By default, the function returns real and imaginary components as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object. 60 61 ```javascript 62 var Float64Array = require( '@stdlib/array/float64' ); 63 64 var out = new Float64Array( 2 ); 65 66 var v = cinv( out, 2.0, 4.0 ); 67 // returns <Float64Array>[ 0.1, -0.2 ] 68 69 var bool = ( v === out ); 70 // returns true 71 ``` 72 73 </section> 74 75 <!-- /.usage --> 76 77 <section class="examples"> 78 79 ## Examples 80 81 <!-- eslint no-undef: "error" --> 82 83 ```javascript 84 var Complex128 = require( '@stdlib/complex/float64' ); 85 var randu = require( '@stdlib/random/base/randu' ); 86 var round = require( '@stdlib/math/base/special/round' ); 87 var real = require( '@stdlib/complex/real' ); 88 var imag = require( '@stdlib/complex/imag' ); 89 var cinv = require( '@stdlib/math/base/special/cinv' ); 90 91 var re; 92 var im; 93 var z1; 94 var z2; 95 var o; 96 var i; 97 98 for ( i = 0; i < 100; i++ ) { 99 re = round( randu()*100.0 ) - 50.0; 100 im = round( randu()*100.0 ) - 50.0; 101 z1 = new Complex128( re, im ); 102 103 o = cinv( real(z1), imag(z1) ); 104 z2 = new Complex128( o[ 0 ], o[ 1 ] ); 105 106 console.log( '1.0 / (%s) = %s', z1.toString(), z2.toString() ); 107 } 108 ``` 109 110 </section> 111 112 <!-- /.examples --> 113 114 * * * 115 116 <section class="references"> 117 118 ## References 119 120 - Smith, Robert L. 1962. "Algorithm 116: Complex Division." _Commun. ACM_ 5 (8). New York, NY, USA: ACM: 435. doi:[10.1145/368637.368661][@smith:1962a]. 121 - Stewart, G. W. 1985. "A Note on Complex Division." _ACM Trans. Math. Softw._ 11 (3). New York, NY, USA: ACM: 238–41. doi:[10.1145/214408.214414][@stewart:1985a]. 122 - Priest, Douglas M. 2004. "Efficient Scaling for Complex Division." _ACM Trans. Math. Softw._ 30 (4). New York, NY, USA: ACM: 389–401. doi:[10.1145/1039813.1039814][@priest:2004a]. 123 - Baudin, Michael, and Robert L. Smith. 2012. "A Robust Complex Division in Scilab." _arXiv_ abs/1210.4539 \[cs.MS] (October): 1–25. [<https://arxiv.org/abs/1210.4539>][@baudin:2012a]. 124 125 </section> 126 127 <!-- /.references --> 128 129 <section class="links"> 130 131 [@smith:1962a]: https://doi.org/10.1145/368637.368661 132 133 [@stewart:1985a]: https://doi.org/10.1145/214408.214414 134 135 [@priest:2004a]: https://doi.org/10.1145/1039813.1039814 136 137 [@baudin:2012a]: https://arxiv.org/abs/1210.4539 138 139 </section> 140 141 <!-- /.links -->