Source Code Cross Referenced for MatrixUtils.java in  » Science » Apache-commons-math-1.1 » org » apache » commons » math » linear » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Apache commons math 1.1 » org.apache.commons.math.linear 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004 The Apache Software Foundation.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.apache.commons.math.linear;
018:
019:        import java.math.BigDecimal;
020:
021:        /**
022:         * A collection of static methods that operate on or return matrices.
023:         * 
024:         * @version $Revision: 209143 $ $Date: 2005-07-04 16:29:23 -0700 (Mon, 04 Jul 2005) $
025:         */
026:        public class MatrixUtils {
027:
028:            /**
029:             * Default constructor.  Package scope to prevent unwanted instantiation. 
030:             */
031:            public MatrixUtils() {
032:                super ();
033:            }
034:
035:            /**
036:             * Returns a {@link RealMatrix} whose entries are the the values in the
037:             * the input array.  The input array is copied, not referenced.
038:             * 
039:             * @param data input array
040:             * @return  RealMatrix containing the values of the array
041:             * @throws IllegalArgumentException if <code>data</code> is not rectangular
042:             *  (not all rows have the same length) or empty
043:             * @throws NullPointerException if data is null
044:             */
045:            public static RealMatrix createRealMatrix(double[][] data) {
046:                return new RealMatrixImpl(data);
047:            }
048:
049:            /**
050:             * Returns <code>dimension x dimension</code> identity matrix.
051:             *
052:             * @param dimension dimension of identity matrix to generate
053:             * @return identity matrix
054:             * @throws IllegalArgumentException if dimension is not positive
055:             * @since 1.1
056:             */
057:            public static RealMatrix createRealIdentityMatrix(int dimension) {
058:                RealMatrixImpl out = new RealMatrixImpl(dimension, dimension);
059:                double[][] d = out.getDataRef();
060:                for (int row = 0; row < dimension; row++) {
061:                    for (int col = 0; col < dimension; col++) {
062:                        d[row][col] = row == col ? 1d : 0d;
063:                    }
064:                }
065:                return out;
066:            }
067:
068:            /**
069:             * Returns a {@link BigMatrix} whose entries are the the values in the
070:             * the input array.  The input array is copied, not referenced.
071:             * 
072:             * @param data input array
073:             * @return  RealMatrix containing the values of the array
074:             * @throws IllegalArgumentException if <code>data</code> is not rectangular
075:             *  (not all rows have the same length) or empty
076:             * @throws NullPointerException if data is null
077:             */
078:            public static BigMatrix createBigMatrix(double[][] data) {
079:                return new BigMatrixImpl(data);
080:            }
081:
082:            /**
083:             * Returns a {@link BigMatrix} whose entries are the the values in the
084:             * the input array.  The input array is copied, not referenced.
085:             * 
086:             * @param data input array
087:             * @return  RealMatrix containing the values of the array
088:             * @throws IllegalArgumentException if <code>data</code> is not rectangular
089:             *  (not all rows have the same length) or empty
090:             * @throws NullPointerException if data is null
091:             */
092:            public static BigMatrix createBigMatrix(BigDecimal[][] data) {
093:                return new BigMatrixImpl(data);
094:            }
095:
096:            /**
097:             * Returns a {@link BigMatrix} whose entries are the the values in the
098:             * the input array.  The input array is copied, not referenced.
099:             * 
100:             * @param data input array
101:             * @return  RealMatrix containing the values of the array
102:             * @throws IllegalArgumentException if <code>data</code> is not rectangular
103:             *  (not all rows have the same length) or empty
104:             * @throws NullPointerException if data is null
105:             */
106:            public static BigMatrix createBigMatrix(String[][] data) {
107:                return new BigMatrixImpl(data);
108:            }
109:
110:            /**
111:             * Creates a row {@link RealMatrix} using the data from the input
112:             * array. 
113:             * 
114:             * @param rowData the input row data
115:             * @return a 1 x rowData.length RealMatrix
116:             * @throws IllegalArgumentException if <code>rowData</code> is empty
117:             * @throws NullPointerException if <code>rowData</code>is null
118:             */
119:            public static RealMatrix createRowRealMatrix(double[] rowData) {
120:                int nCols = rowData.length;
121:                double[][] data = new double[1][nCols];
122:                System.arraycopy(rowData, 0, data[0], 0, nCols);
123:                return new RealMatrixImpl(data);
124:            }
125:
126:            /**
127:             * Creates a row {@link BigMatrix} using the data from the input
128:             * array. 
129:             * 
130:             * @param rowData the input row data
131:             * @return a 1 x rowData.length BigMatrix
132:             * @throws IllegalArgumentException if <code>rowData</code> is empty
133:             * @throws NullPointerException if <code>rowData</code>is null
134:             */
135:            public static BigMatrix createRowBigMatrix(double[] rowData) {
136:                int nCols = rowData.length;
137:                double[][] data = new double[1][nCols];
138:                System.arraycopy(rowData, 0, data[0], 0, nCols);
139:                return new BigMatrixImpl(data);
140:            }
141:
142:            /**
143:             * Creates a row {@link BigMatrix} using the data from the input
144:             * array. 
145:             * 
146:             * @param rowData the input row data
147:             * @return a 1 x rowData.length BigMatrix
148:             * @throws IllegalArgumentException if <code>rowData</code> is empty
149:             * @throws NullPointerException if <code>rowData</code>is null
150:             */
151:            public static BigMatrix createRowBigMatrix(BigDecimal[] rowData) {
152:                int nCols = rowData.length;
153:                BigDecimal[][] data = new BigDecimal[1][nCols];
154:                System.arraycopy(rowData, 0, data[0], 0, nCols);
155:                return new BigMatrixImpl(data);
156:            }
157:
158:            /**
159:             * Creates a row {@link BigMatrix} using the data from the input
160:             * array. 
161:             * 
162:             * @param rowData the input row data
163:             * @return a 1 x rowData.length BigMatrix
164:             * @throws IllegalArgumentException if <code>rowData</code> is empty
165:             * @throws NullPointerException if <code>rowData</code>is null
166:             */
167:            public static BigMatrix createRowBigMatrix(String[] rowData) {
168:                int nCols = rowData.length;
169:                String[][] data = new String[1][nCols];
170:                System.arraycopy(rowData, 0, data[0], 0, nCols);
171:                return new BigMatrixImpl(data);
172:            }
173:
174:            /**
175:             * Creates a column {@link RealMatrix} using the data from the input
176:             * array.
177:             * 
178:             * @param columnData  the input column data
179:             * @return a columnData x 1 RealMatrix
180:             * @throws IllegalArgumentException if <code>columnData</code> is empty
181:             * @throws NullPointerException if <code>columnData</code>is null
182:             */
183:            public static RealMatrix createColumnRealMatrix(double[] columnData) {
184:                int nRows = columnData.length;
185:                double[][] data = new double[nRows][1];
186:                for (int row = 0; row < nRows; row++) {
187:                    data[row][0] = columnData[row];
188:                }
189:                return new RealMatrixImpl(data);
190:            }
191:
192:            /**
193:             * Creates a column {@link BigMatrix} using the data from the input
194:             * array.
195:             * 
196:             * @param columnData  the input column data
197:             * @return a columnData x 1 BigMatrix
198:             * @throws IllegalArgumentException if <code>columnData</code> is empty
199:             * @throws NullPointerException if <code>columnData</code>is null
200:             */
201:            public static BigMatrix createColumnBigMatrix(double[] columnData) {
202:                int nRows = columnData.length;
203:                double[][] data = new double[nRows][1];
204:                for (int row = 0; row < nRows; row++) {
205:                    data[row][0] = columnData[row];
206:                }
207:                return new BigMatrixImpl(data);
208:            }
209:
210:            /**
211:             * Creates a column {@link BigMatrix} using the data from the input
212:             * array.
213:             * 
214:             * @param columnData  the input column data
215:             * @return a columnData x 1 BigMatrix
216:             * @throws IllegalArgumentException if <code>columnData</code> is empty
217:             * @throws NullPointerException if <code>columnData</code>is null
218:             */
219:            public static BigMatrix createColumnBigMatrix(
220:                    BigDecimal[] columnData) {
221:                int nRows = columnData.length;
222:                BigDecimal[][] data = new BigDecimal[nRows][1];
223:                for (int row = 0; row < nRows; row++) {
224:                    data[row][0] = columnData[row];
225:                }
226:                return new BigMatrixImpl(data);
227:            }
228:
229:            /**
230:             * Creates a column {@link BigMatrix} using the data from the input
231:             * array.
232:             * 
233:             * @param columnData  the input column data
234:             * @return a columnData x 1 BigMatrix
235:             * @throws IllegalArgumentException if <code>columnData</code> is empty
236:             * @throws NullPointerException if <code>columnData</code>is null
237:             */
238:            public static BigMatrix createColumnBigMatrix(String[] columnData) {
239:                int nRows = columnData.length;
240:                String[][] data = new String[nRows][1];
241:                for (int row = 0; row < nRows; row++) {
242:                    data[row][0] = columnData[row];
243:                }
244:                return new BigMatrixImpl(data);
245:            }
246:
247:            /**
248:             * Returns <code>dimension x dimension</code> identity matrix.
249:             *
250:             * @param dimension dimension of identity matrix to generate
251:             * @return identity matrix
252:             * @throws IllegalArgumentException if dimension is not positive
253:             * @since 1.1
254:             */
255:            public static BigMatrix createBigIdentityMatrix(int dimension) {
256:                BigMatrixImpl out = new BigMatrixImpl(dimension, dimension);
257:                BigDecimal[][] d = out.getDataRef();
258:                for (int row = 0; row < dimension; row++) {
259:                    for (int col = 0; col < dimension; col++) {
260:                        d[row][col] = row == col ? BigMatrixImpl.ONE
261:                                : BigMatrixImpl.ZERO;
262:                    }
263:                }
264:                return out;
265:            }
266:
267:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.