annotate libs/commons-math-2.1/docs/userguide/complex.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 - Complex Numbers</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 <a href="../userguide/utilities.html">Utilities</a>
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 <strong>Complex Numbers</strong>
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="a7_Complex_Numbers"></a>7 Complex Numbers</h2>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
150 <div class="section"><h3><a name="a7.1_Overview"></a>7.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 complex packages provides a complex number type as well as complex
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
153 versions of common transcendental functions and complex number
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
154 formatting.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
155 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
156 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
157 <div class="section"><h3><a name="a7.2_Complex_Numbers"></a>7.2 Complex Numbers</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
158 <p><a href="../apidocs/org/apache/commons/math/complex/Complex.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
159 org.apache.commons.math.complex.Complex</a> provides a complex number
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
160 type that forms the basis for the complex functionality found in
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
161 commons-math.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
162 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
163 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
164 Complex functions and arithmetic operations are implemented in
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
165 commons-math by applying standard computational formulas and
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
166 following the rules for <code>java.lang.Double</code> arithmetic in
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
167 handling infinite and <code>NaN</code> values. No attempt is made
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
168 to comply with ANSII/IEC C99x Annex G or any other standard for
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
169 Complex arithmetic. See the class and method javadocs for the
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
170 <a href="../apidocs/org/apache/commons/math/complex/Complex.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
171 Complex</a> and
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
172 <a href="../apidocs/org/apache/commons/math/complex/ComplexUtils.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
173 ComplexUtils</a> classes for details on computing formulas.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
174 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
175 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
176 To create a complex number, simply call the constructor passing in two
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
177 floating-point arguments, the first being the real part of the
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
178 complex number and the second being the imaginary part:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
179 <div class="source"><pre>Complex c = new Complex(1.0, 3.0); // 1 + 3i</pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
180 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
181 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
182 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
183 Complex numbers may also be created from polar representations
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
184 using the <code>polar2Complex</code> method in
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
185 <code>ComplexUtils</code>.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
186 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
187 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
188 The <code>Complex</code> class provides basic unary and binary
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
189 complex number operations. These operations provide the means to add,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
190 subtract, multiply and divide complex numbers along with other
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
191 complex number functions similar to the real number functions found in
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
192 <code>java.math.BigDecimal</code>:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
193 <div class="source"><pre>Complex lhs = new Complex(1.0, 3.0);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
194 Complex rhs = new Complex(2.0, 5.0);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
195
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
196 Complex answer = lhs.add(rhs); // add two complex numbers
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
197 answer = lhs.subtract(rhs); // subtract two complex numbers
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
198 answer = lhs.abs(); // absolute value
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
199 answer = lhs.conjugate(rhs); // complex conjugate</pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
200 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
201 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
202 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
203 <div class="section"><h3><a name="a7.3_Complex_Transcendental_Functions"></a>7.3 Complex Transcendental Functions</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
204 <p><a href="../apidocs/org/apache/commons/math/complex/Complex.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
205 org.apache.commons.math.complex.Complex</a> also provides
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
206 implementations of serveral transcendental functions involving complex
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
207 number arguments. Prior to version 1.2, these functions were provided
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
208 by <a href="../apidocs/org/apache/commons/math/complex/ComplexUtils.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
209 org.apache.commons.math.complex.ComplexUtils</a> in a way similar to the real
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
210 number functions found in <code>java.lang.Math</code>, but this has been
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
211 deprecated. These operations provide the means to compute the log, sine,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
212 tangent, and other complex values :
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
213 <div class="source"><pre>Complex first = new Complex(1.0, 3.0);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
214 Complex second = new Complex(2.0, 5.0);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
215
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
216 Complex answer = first.log(); // natural logarithm.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
217 answer = first.cos(); // cosine
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
218 answer = first.pow(second); // first raised to the power of second</pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
219 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
220 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
221 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
222 <div class="section"><h3><a name="a7.4_Complex_Formatting_and_Parsing"></a>7.4 Complex Formatting and Parsing</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
223 <p><code>Complex</code> instances can be converted to and from strings
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
224 using the<a href="../apidocs/org/apache/commons/math/complex/ComplexFormat.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
225 org.apache.commons.math.complex.ComplexFormat</a> class.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
226 <code>ComplexFormat</code> is a <code>java.text.Format</code>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
227 extension and, as such, is used like other formatting objects (e.g.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
228 <code>java.text.SimpleDateFormat</code>):
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
229 <div class="source"><pre>ComplexFormat format = new ComplexFormat(); // default format
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
230 Complex c = new Complex(1.1111, 2.2222);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
231 String s = format.format(c); // s contains &quot;1.11 + 2.22i&quot;</pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
232 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
233 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
234 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
235 To customize the formatting output, one or two
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
236 <code>java.text.NumberFormat</code> instances can be used to construct
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
237 a <code>ComplexFormat</code>. These number formats control the
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
238 formatting of the real and imaginary values of the complex number:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
239 <div class="source"><pre>NumberFormat nf = NumberFormat.getInstance();
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
240 nf.setMinimumFractionDigits(3);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
241 nf.setMaximumFractionDigits(3);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
242
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
243 // create complex format with custom number format
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
244 // when one number format is used, both real and
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
245 // imaginary parts are formatted the same
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
246 ComplexFormat cf = new ComplexFormat(nf);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
247 Complex c = new Complex(1.11, 2.2222);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
248 String s = format.format(c); // s contains &quot;1.110 + 2.222i&quot;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
249
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
250 NumberFormat nf2 = NumberFormat.getInstance();
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
251 nf.setMinimumFractionDigits(1);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
252 nf.setMaximumFractionDigits(1);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
253
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
254 // create complex format with custom number formats
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
255 cf = new ComplexFormat(nf, nf2);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
256 s = format.format(c); // s contains &quot;1.110 + 2.2i&quot;</pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
257 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
258 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
259 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
260 Another formatting customization provided by
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
261 <code>ComplexFormat</code> is the text used for the imaginary
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
262 designation. By default, the imaginary notation is &quot;i&quot; but, it can be
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
263 manipulated using the <code>setImaginaryCharacter</code> method.
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 Formatting inverse operation, parsing, can also be performed by
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
267 <code>ComplexFormat</code>. Parse a complex number from a string,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
268 simply call the <code>parse</code> method:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
269 <div class="source"><pre>ComplexFormat cf = new ComplexFormat();
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
270 Complex c = cf.parse(&quot;1.110 + 2.222i&quot;);</pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
271 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
272 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
273 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
274 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
275
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
276 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
277 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
278 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
279 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
280 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
281 <div id="footer">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
282 <div class="xright">&#169;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
283 2003-2010
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
284
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
285
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
286
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
287
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
288
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
289
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
290
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
291
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
292
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
293 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
294 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
295 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
296 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
297 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
298 </body>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
299 </html>