-
-
Notifications
You must be signed in to change notification settings - Fork 804
/
Copy pathrepl.txt
91 lines (73 loc) · 2.16 KB
/
repl.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{{alias}}( generator[, options] )
Evaluates the continued fraction approximation for the supplied series
generator using the modified Lentz algorithm.
`generator` can be either a function which returns an array with two
elements, the `a` and `b` terms of the fraction, or an ES6 Generator object.
By default, the function computes
a1
---------------
b1 + a2
----------
b2 + a3
-----
b3 + ...
To evaluate
b0 + a1
---------------
b1 + a2
----------
b2 + a3
-----
b3 + ...
set the `keep` option to `true`.
Parameters
----------
generator: Function
Function returning terms of continued fraction expansion.
options: Object (optional)
Options.
options.maxIter: integer (optional)
Maximum number of iterations. Default: `1000000`.
options.tolerance: number (optional)
Further terms are only added as long as the next term is greater than
current term times the tolerance. Default: `2.22e-16`.
options.keep: boolean (optional)
Boolean indicating whether to keep the `b0` term in the continued
fraction. Default: `false`.
Returns
-------
out: number
Value of continued fraction.
Examples
--------
// Continued fraction for (e-1)^(-1):
> function closure() {
... var i = 0;
... return function() {
... i += 1;
... return [ i, i ];
... };
... };
> var gen = closure();
> var out = {{alias}}( gen )
~0.582
// Using an ES6 generator:
> function* generator() {
... var i = 0;
... while ( true ) {
... i += 1;
... yield [ i, i ];
... }
... };
> gen = generator();
> out = {{alias}}( gen )
~0.582
// Set options:
> out = {{alias}}( generator(), { 'keep': true } )
~1.718
> out = {{alias}}( generator(), { 'maxIter': 10 } )
~0.582
> out = {{alias}}( generator(), { 'tolerance': 1e-1 } )
~0.579
See Also
--------