annotate libs/commons-math-2.1/docs/userguide/linear.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 - Linear Algebra</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 <strong>Linear Algebra</strong>
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 <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="a3_Linear_Algebra"></a>3 Linear Algebra</h2>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
150 <div class="section"><h3><a name="a3.1_Overview"></a>3.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 Linear algebra support in commons-math provides operations on real matrices
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
153 (both dense and sparse matrices are supported) and vectors. It features basic
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
154 operations (addition, subtraction ...) and decomposition algorithms that can
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
155 be used to solve linear systems either in exact sense and in least squares sense.
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="a3.2_Real_matrices"></a>3.2 Real matrices</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
159 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
160 The <a href="../apidocs/org/apache/commons/math/linear/RealMatrix.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
161 RealMatrix</a> interface represents a matrix with real numbers as
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
162 entries. The following basic matrix operations are supported:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
163 <ul><li>Matrix addition, subtraction, multiplication</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
164 <li>Scalar addition and multiplication</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
165 <li>transpose</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
166 <li>Norm and Trace</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
167 <li>Operation on a vector</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
168 </ul>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
169 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
170 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
171 Example:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
172 <div class="source"><pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
173 // Create a real matrix with two rows and three columns
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
174 double[][] matrixData = { {1d,2d,3d}, {2d,5d,3d}};
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
175 RealMatrix m = new Array2DRowRealMatrix(matrixData);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
176
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
177 // One more with three rows, two columns
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
178 double[][] matrixData2 = { {1d,2d}, {2d,5d}, {1d, 7d}};
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
179 RealMatrix n = new Array2DRowRealMatrix(matrixData2);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
180
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
181 // Note: The constructor copies the input double[][] array.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
182
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
183 // Now multiply m by n
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
184 RealMatrix p = m.multiply(n);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
185 System.out.println(p.getRowDimension()); // 2
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
186 System.out.println(p.getColumnDimension()); // 2
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
187
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
188 // Invert p, using LU decomposition
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
189 RealMatrix pInverse = new LUDecompositionImpl(p).getSolver().getInverse();
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
190 </pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
191 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
192 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
193 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
194 The three main implementations of the interface are <a href="../apidocs/org/apache/commons/math/linear/Array2DRowRealMatrix.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
195 Array2DRowRealMatrix</a> and <a href="../apidocs/org/apache/commons/math/linear/BlockRealMatrix.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
196 BlockRealMatrix</a> for dense matrices (the second one being more suited to
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
197 dimensions above 50 or 100) and <a href="../apidocs/org/apache/commons/math/linear/SparseRealMatrix.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
198 SparseRealMatrix</a> for sparse matrices.
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="a3.3_Real_vectors"></a>3.3 Real vectors</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/linear/RealVector.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
204 RealVector</a> interface represents a vector with real numbers as
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
205 entries. The following basic matrix operations are supported:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
206 <ul><li>Vector addition, subtraction</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
207 <li>Element by element multiplication, division</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
208 <li>Scalar addition, subtraction, multiplication, division and power</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
209 <li>Mapping of mathematical functions (cos, sin ...)</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
210 <li>Dot product, outer product</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
211 <li>Distance and norm according to norms L1, L2 and Linf</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
212 </ul>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
213 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
214 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
215 The <a href="../apidocs/org/apache/commons/math/linear/RealVectorFormat.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
216 RealVectorFormat</a> class handles input/output of vectors in a customizable
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
217 textual format.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
218 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
219 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
220 <div class="section"><h3><a name="a3.4_Solving_linear_systems"></a>3.4 Solving linear systems</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
221 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
222 The <code>solve()</code> methods of the <a href="../apidocs/org/apache/commons/math/linear/DecompositionSolver.html">DecompositionSolver</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
223 interface support solving linear systems of equations of the form AX=B, either
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
224 in linear sense or in least square sense. A <code>RealMatrix</code> instance is
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
225 used to represent the coefficient matrix of the system. Solving the system is a
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
226 two phases process: first the coefficient matrix is decomposed in some way and
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
227 then a solver built from the decomposition solves the system. This allows to
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
228 compute the decomposition and build the solver only once if several systems have
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
229 to be solved with the same coefficient matrix.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
230 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
231 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
232 For example, to solve the linear system
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
233 <pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
234 2x + 3y - 2z = 1
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
235 -x + 7y + 6x = -2
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
236 4x - 3y - 5z = 1
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
237 </pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
238 Start by decomposing the coefficient matrix A (in this case using LU decomposition)
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
239 and build a solver
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
240 <div class="source"><pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
241 RealMatrix coefficients =
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
242 new Array2DRowRealMatrix(new double[][] { { 2, 3, -2 }, { -1, 7, 6 }, { 4, -3, -5 } },
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
243 false);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
244 DecompositionSolver solver = new LUDecompositionImpl(coefficients).getSolver();
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
245 </pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
246 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
247
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
248 Next create a <code>RealVector</code> array to represent the constant
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
249 vector B and use <code>solve(RealVector)</code> to solve the system
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
250 <div class="source"><pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
251 RealVector constants = new RealVectorImpl(new double[] { 1, -2, 1 }, false);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
252 RealVector solution = solver.solve(constants);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
253 </pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
254 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
255
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
256 The <code>solution</code> vector will contain values for x
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
257 (<code>solution.getEntry(0)</code>), y (<code>solution.getEntry(1)</code>),
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
258 and z (<code>solution.getEntry(2)</code>) that solve the system.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
259 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
260 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
261 Each type of decomposition has its specific semantics and constraints on
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
262 the coefficient matrix as shown in the following table. For algorithms that
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
263 solve AX=B in least squares sense the value returned for X is such that the
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
264 residual AX-B has minimal norm. If an exact solution exist (i.e. if for some
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
265 X the residual AX-B is exactly 0), then this exact solution is also the solution
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
266 in least square sense. This implies that algorithms suited for least squares
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
267 problems can also be used to solve exact problems, but the reverse is not true.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
268 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
269 <p><table class="bodyTable"><tr class="a"><td><font size="+2">Decomposition algorithms</font></td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
270 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
271 <tr class="b"><font size="+1"><td>Name</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
272 <td>coefficients matrix</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
273 <td>problem type</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
274 </font></tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
275 <tr class="a"><td><a href="../apidocs/org/apache/commons/math/linear/LUDecomposition.html">LU</a></td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
276 <td>square</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
277 <td>exact solution only</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
278 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
279 <tr class="b"><td><a href="../apidocs/org/apache/commons/math/linear/CholeskyDecomposition.html">Cholesky</a></td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
280 <td>symmetric positive definite</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
281 <td>exact solution only</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
282 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
283 <tr class="a"><td><a href="../apidocs/org/apache/commons/math/linear/QRDecomposition.html">QR</a></td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
284 <td>any</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
285 <td>least squares solution</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
286 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
287 <tr class="b"><td><a href="../apidocs/org/apache/commons/math/linear/EigenDecomposition.html">eigen decomposition</a></td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
288 <td>square</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
289 <td>exact solution only</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
290 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
291 <tr class="a"><td><a href="../apidocs/org/apache/commons/math/linear/SingularValueDecomposition.html">SVD</a></td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
292 <td>any</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
293 <td>least squares solution</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
294 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
295 </table>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
296 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
297 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
298 It is possible to use a simple array of double instead of a <code>RealVector</code>.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
299 In this case, the solution will be provided also as an array of double.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
300 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
301 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
302 It is possible to solve multiple systems with the same coefficient matrix
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
303 in one method call. To do this, create a matrix whose column vectors correspond
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
304 to the constant vectors for the systems to be solved and use <code>solve(RealMatrix),</code>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
305 which returns a matrix with column vectors representing the solutions.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
306 </p>
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="section"><h3><a name="a3.5_Eigenvalueseigenvectors_and_singular_valuessingular_vectors"></a>3.5 Eigenvalues/eigenvectors and singular values/singular vectors</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
309 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
310 Decomposition algorithms may be used for themselves and not only for linear system solving.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
311 This is of prime interest with eigen decomposition and singular value decomposition.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
312 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
313 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
314 The <code>getEigenvalue()</code>, <code>getEigenvalues()</code>, <code>getEigenVector()</code>,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
315 <code>getV()</code>, <code>getD()</code> and <code>getVT()</code> methods of the
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
316 <code>EigenDecomposition</code> interface support solving eigenproblems of the form
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
317 AX = lambda X where lambda is a real scalar.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
318 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
319 <p>The <code>getSingularValues()</code>, <code>getU()</code>, <code>getS()</code> and
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
320 <code>getV()</code> methods of the <code>SingularValueDecomposition</code> interface
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
321 allow to solve singular values problems of the form AXi = lambda Yi where lambda is a
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
322 real scalar, and where the Xi and Yi vectors form orthogonal bases of their respective
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
323 vector spaces (which may have different dimensions).
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
324 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
325 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
326 <div class="section"><h3><a name="a3.6_Non-real_fields_complex_fractions_..."></a>3.6 Non-real fields (complex, fractions ...)</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
327 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
328 In addition to the real field, matrices and vectors using non-real <a href="../apidocs/org/apache/commons/math/FieldElement.html">field elements</a> can be used.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
329 The fields already supported by the library are:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
330 <ul><li><a href="../apidocs/org/apache/commons/math/complex/Complex.html">Complex</a></li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
331 <li><a href="../apidocs/org/apache/commons/math/fraction/Fraction.html">Fraction</a></li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
332 <li><a href="../apidocs/org/apache/commons/math/fraction/BigFraction.html">BigFraction</a></li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
333 <li><a href="../apidocs/org/apache/commons/math/util/BigReal.html">BigReal</a></li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
334 </ul>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
335 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
336 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
337 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
338
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
339 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
340 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
341 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
342 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
343 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
344 <div id="footer">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
345 <div class="xright">&#169;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
346 2003-2010
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
347
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
348
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
349
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
350
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
351
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
352
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
353
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
354
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
355
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
356 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
357 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
358 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
359 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
360 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
361 </body>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
362 </html>