annotate libs/commons-math-2.1/docs/userguide/utilities.html @ 10:5f2c5fb36e93

commons-math-2.1 added
author dwinter
date Tue, 04 Jan 2011 10:00:53 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
2
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
3
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
4
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
5
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
6
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
7
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
8
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
9
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
10
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
11
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
12
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
13 <html xmlns="http://www.w3.org/1999/xhtml">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
14 <head>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
15 <title>Math - The Commons Math User Guide - Utilites</title>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
16 <style type="text/css" media="all">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
17 @import url("../css/maven-base.css");
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
18 @import url("../css/maven-theme.css");
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
19 @import url("../css/site.css");
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
20 </style>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
21 <link rel="stylesheet" href="../css/print.css" type="text/css" media="print" />
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
22 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
23 </head>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
24 <body class="composite">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
25 <div id="banner">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
26 <span id="bannerLeft">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
27
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
28 Commons Math User Guide
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
29
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
30 </span>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
31 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
32 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
33 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
34 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
35 <div id="breadcrumbs">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
36
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
37
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
38
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
39
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
40
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
41
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
42
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
43
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
44 <div class="xright">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
45
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
46
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
47
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
48
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
49
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
50
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
51
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
52 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
53 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
54 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
55 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
56 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
57 <div id="leftColumn">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
58 <div id="navcolumn">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
59
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
60
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
61
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
62
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
63
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
64
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
65
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
66
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
67 <h5>User Guide</h5>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
68 <ul>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
69
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
70 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
71 <a href="../userguide/index.html">Contents</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
72 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
73
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
74 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
75 <a href="../userguide/overview.html">Overview</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
76 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
77
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
78 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
79 <a href="../userguide/stat.html">Statistics</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
80 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
81
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
82 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
83 <a href="../userguide/random.html">Data Generation</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
84 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
85
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
86 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
87 <a href="../userguide/linear.html">Linear Algebra</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
88 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
89
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
90 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
91 <a href="../userguide/analysis.html">Numerical Analysis</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
92 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
93
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
94 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
95 <a href="../userguide/special.html">Special Functions</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
96 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
97
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
98 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
99 <strong>Utilities</strong>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
100 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
101
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
102 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
103 <a href="../userguide/complex.html">Complex Numbers</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
104 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
105
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
106 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
107 <a href="../userguide/distribution.html">Distributions</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
108 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
109
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
110 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
111 <a href="../userguide/fraction.html">Fractions</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
112 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
113
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
114 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
115 <a href="../userguide/transform.html">Transform Methods</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
116 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
117
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
118 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
119 <a href="../userguide/geometry.html">3D Geometry</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
120 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
121
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
122 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
123 <a href="../userguide/optimization.html">Optimization</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
124 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
125
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
126 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
127 <a href="../userguide/ode.html">Ordinary Differential Equations</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
128 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
129
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
130 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
131 <a href="../userguide/genetics.html">Genetic Algorithms</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
132 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
133 </ul>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
134 <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
135 <img alt="Built by Maven" src="../images/logos/maven-feather.png"></img>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
136 </a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
137
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
138
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
139
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
140
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
141
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
142
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
143
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
144
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
145 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
146 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
147 <div id="bodyColumn">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
148 <div id="contentBox">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
149 <div class="section"><h2><a name="a6_Utilities"></a>6 Utilities</h2>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
150 <div class="section"><h3><a name="a6.1_Overview"></a>6.1 Overview</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
151 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
152 The <a href="../apidocs/org/apache/commons/math/util/package-summary.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
153 org.apache.commons.math.util</a> package collects a group of array utilities,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
154 value transformers, and numerical routines used by implementation classes in
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
155 commons-math.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
156 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
157 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
158 <div class="section"><h3><a name="a6.2_Double_array_utilities"></a>6.2 Double array utilities</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
159 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
160 To maintain statistics based on a &quot;rolling&quot; window of values, a resizable
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
161 array implementation was developed and is provided for reuse in the
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
162 <code>util</code> package. The core functionality provided is described in
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
163 the documentation for the interface,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
164 <a href="../apidocs/org/apache/commons/math/util/DoubleArray.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
165 org.apache.commons.math.util.DoubleArray.</a> This interface adds one
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
166 method, <code>addElementRolling(double)</code> to basic list accessors.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
167 The <code>addElementRolling</code> method adds an element
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
168 (the actual parameter) to the end of the list and removes the first element
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
169 in the list.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
170 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
171 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
172 The <a href="../apidocs/org/apache/commons/math/util/ResizableDoubleArray.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
173 org.apache.commons.math.util.ResizableDoubleArray</a> class provides a
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
174 configurable, array-backed implementation of the <code>DoubleArray</code>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
175 interface. When <code>addElementRolling</code> is invoked, the underlying
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
176 array is expanded if necessary, the new element is added to the end of the
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
177 array and the &quot;usable window&quot; of the array is moved forward, so that
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
178 the first element is effectively discarded, what was the second becomes the
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
179 first, and so on. To efficiently manage storage, two maintenance
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
180 operations need to be periodically performed -- orphaned elements at the
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
181 beginning of the array need to be reclaimed and space for new elements at
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
182 the end needs to be created. Both of these operations are handled
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
183 automatically, with frequency / effect driven by the configuration
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
184 properties <code>expansionMode</code>, <code>expansionFactor</code> and
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
185 <code>contractionCriteria.</code> See
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
186 <a href="../apidocs/org/apache/commons/math/util/ResizableDoubleArray.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
187 ResizableDoubleArray</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
188 for details.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
189 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
190 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
191 <div class="section"><h3><a name="a6.3_intdouble_hash_map"></a>6.3 int/double hash map</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
192 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
193 The <a href="../apidocs/org/apache/commons/math/util/OpenIntToDoubleHashMap.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
194 org.apache.commons.math.util.OpenIntToDoubleHashMap</a> class provides a specialized
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
195 hash map implementation for int/double. This implementation has a much smaller memory
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
196 overhead than standard <code>java.util.HashMap</code> class. It uses open addressing
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
197 and primitive arrays, which greatly reduces the number of intermediate objects and
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
198 improve data locality.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
199 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
200 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
201 <div class="section"><h3><a name="a6.4_Continued_Fractions"></a>6.4 Continued Fractions</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
202 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
203 The <a href="../apidocs/org/apache/commons/math/util/ContinuedFraction.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
204 org.apache.commons.math.util.ContinuedFraction</a> class provides a generic
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
205 way to create and evaluate continued fractions. The easiest way to create a
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
206 continued fraction is to subclass <code>ContinuedFraction</code> and
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
207 override the <code>getA</code> and <code>getB</code> methods which return
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
208 the continued fraction terms. The precise definition of these terms is
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
209 explained in <a href="http://mathworld.wolfram.com/ContinuedFraction.html" class="externalLink">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
210 Continued Fraction, equation (1)</a> from MathWorld.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
211 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
212 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
213 As an example, the constant Pi could be computed using the continued fraction
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
214 defined at <a href="http://functions.wolfram.com/Constants/Pi/10/0002/" class="externalLink">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
215 http://functions.wolfram.com/Constants/Pi/10/0002/</a>. The following
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
216 anonymous class provides the implementation:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
217 <div class="source"><pre>ContinuedFraction c = new ContinuedFraction() {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
218 public double getA(int n, double x) {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
219 switch(n) {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
220 case 0: return 3.0;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
221 default: return 6.0;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
222 }
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
223 }
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
224
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
225 public double getB(int n, double x) {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
226 double y = (2.0 * n) - 1.0;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
227 return y * y;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
228 }
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
229 }</pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
230 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
231 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
232 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
233 Then, to evalute Pi, simply call any of the <code>evalute</code> methods
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
234 (Note, the point of evalution in this example is meaningless since Pi is a
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
235 constant).
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
236 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
237 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
238 For a more practical use of continued fractions, consider the exponential
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
239 function with the continued fraction definition of
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
240 <a href="http://functions.wolfram.com/ElementaryFunctions/Exp/10/" class="externalLink">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
241 http://functions.wolfram.com/ElementaryFunctions/Exp/10/</a>. The
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
242 following anonymous class provides its implementation:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
243 <div class="source"><pre>ContinuedFraction c = new ContinuedFraction() {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
244 public double getA(int n, double x) {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
245 if (n % 2 == 0) {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
246 switch(n) {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
247 case 0: return 1.0;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
248 default: return 2.0;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
249 }
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
250 } else {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
251 return n;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
252 }
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
253 }
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
254
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
255 public double getB(int n, double x) {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
256 if (n % 2 == 0) {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
257 return -x;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
258 } else {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
259 return x;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
260 }
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
261 }
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
262 }</pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
263 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
264 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
265 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
266 Then, to evalute <i>e</i><sup>x</sup> for any value x, simply call any of the
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
267 <code>evalute</code> methods.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
268 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
269 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
270 <div class="section"><h3><a name="a6.5_binomial_coefficients_factorials_and_other_common_math_functions"></a>6.5 binomial coefficients, factorials and other common math functions</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
271 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
272 A collection of reusable math functions is provided in the
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
273 <a href="../apidocs/org/apache/commons/math/util/MathUtils.html">MathUtils</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
274 utility class. MathUtils currently includes methods to compute the following: <ul><li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
275 Binomial coeffiecients -- &quot;n choose k&quot; available as an (exact) long value,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
276 <code>binomialCoefficient(int, int)</code> for small n, k; as a double,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
277 <code>binomialCoefficientDouble(int, int)</code> for larger values; and in
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
278 a &quot;super-sized&quot; version, <code>binomialCoefficientLog(int, int)</code>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
279 that returns the natural logarithm of the value.</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
280 <li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
281 Factorials -- like binomial coefficients, these are available as exact long
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
282 values, <code>factorial(int)</code>; doubles,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
283 <code>factorialDouble(int)</code>; or logs, <code>factorialLog(int)</code>. </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
284 <li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
285 Hyperbolic sine and cosine functions --
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
286 <code>cosh(double), sinh(double)</code></li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
287 <li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
288 sign (+1 if argument &gt; 0, 0 if x = 0, and -1 if x &lt; 0) and
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
289 indicator (+1.0 if argument &gt;= 0 and -1.0 if argument &lt; 0) functions
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
290 for variables of all primitive numeric types.</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
291 <li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
292 a hash function, <code>hash(double),</code> returning a long-valued
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
293 hash code for a double value.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
294 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
295 <li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
296 Convience methods to round floating-point number to arbitrary precision.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
297 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
298 <li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
299 Least common multiple and greatest common denominator functions.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
300 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
301 </ul>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
302 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
303 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
304 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
305
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
306 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
307 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
308 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
309 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
310 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
311 <div id="footer">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
312 <div class="xright">&#169;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
313 2003-2010
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
314
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
315
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
316
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
317
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
318
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
319
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
320
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
321
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
322
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
323 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
324 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
325 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
326 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
327 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
328 </body>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
329 </html>