README.md (3573B)
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 # Binet's Formula 22 23 > Evaluate [Binet's formula][fibonacci-number] extended to real numbers. 24 25 <section class="intro"> 26 27 [Binet's formula][fibonacci-number] refers to the closed-form solution for computing the nth [Fibonacci number][fibonacci-number] and may be expressed 28 29 <!-- <equation class="equation" label="eq:binets_formula" align="center" raw="F_n = \frac{\varphi^n - \psi^n}{\sqrt{5}}" alt="Binet's formula"> --> 30 31 <div class="equation" align="center" data-raw-text="F_n = \frac{\varphi^n - \psi^n}{\sqrt{5}}" data-equation="eq:binets_formula"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/binet/docs/img/equation_binets_formula.svg" alt="Binet's formula"> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 where `φ` is the [golden ratio][golden-ratio] and `ψ` is `1 - φ`. To extend [Fibonacci numbers][fibonacci-number] to real numbers, we may express [Binet's formula][fibonacci-number] as 39 40 <!-- <equation class="equation" label="eq:binets_formula_real_numbers" align="center" raw="F_x = \frac{\varphi^x - \varphi^{-x} \cdot \cos(\pi x)}{\sqrt{5}}" alt="Binet's formula extended to real numbers."> --> 41 42 <div class="equation" align="center" data-raw-text="F_x = \frac{\varphi^x - \varphi^{-x} \cdot \cos(\pi x)}{\sqrt{5}}" data-equation="eq:binets_formula_real_numbers"> 43 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/binet/docs/img/equation_binets_formula_real_numbers.svg" alt="Binet's formula extended to real numbers."> 44 <br> 45 </div> 46 47 <!-- </equation> --> 48 49 </section> 50 51 <!-- /.intro --> 52 53 <section class="usage"> 54 55 ## Usage 56 57 ```javascript 58 var binet = require( '@stdlib/math/base/special/binet' ); 59 ``` 60 61 #### binet( x ) 62 63 Evaluates [Binet's formula][fibonacci-number] extended to real numbers. 64 65 ```javascript 66 var v = binet( 0.0 ); 67 // returns 0.0 68 69 v = binet( 1.0 ); 70 // returns 1.0 71 72 v = binet( 2.0 ); 73 // returns 1.0 74 75 v = binet( 3.0 ); 76 // returns 2.0 77 78 v = binet( -1.0 ); 79 // returns 1.0 80 81 v = binet( 3.14 ); 82 // returns ~2.12 83 ``` 84 85 If provided `NaN`, the function returns `NaN`. 86 87 ```javascript 88 var v = binet( NaN ); 89 // returns NaN 90 ``` 91 92 </section> 93 94 <!-- /.usage --> 95 96 <section class="notes"> 97 98 ## Notes 99 100 - The function returns only **approximate** [Fibonacci numbers][fibonacci-number] for nonnegative integers. 101 - The function does **not** return complex numbers, guaranteeing real-valued return values. 102 103 </section> 104 105 <!-- /.notes --> 106 107 <section class="examples"> 108 109 ## Examples 110 111 <!-- eslint no-undef: "error" --> 112 113 ```javascript 114 var binet = require( '@stdlib/math/base/special/binet' ); 115 116 var v; 117 var i; 118 119 for ( i = 0; i < 79; i++ ) { 120 v = binet( i ); 121 console.log( v ); 122 } 123 ``` 124 125 </section> 126 127 <!-- /.examples --> 128 129 <section class="links"> 130 131 [fibonacci-number]: https://en.wikipedia.org/wiki/Fibonacci_number 132 133 [golden-ratio]: https://en.wikipedia.org/wiki/Golden_ratio 134 135 </section> 136 137 <!-- /.links -->