Java Doc for RealMatrixImpl.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 Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.math.linear.RealMatrixImpl

RealMatrixImpl
public class RealMatrixImpl implements RealMatrix,Serializable(Code)
Implementation of RealMatrix using a double[][] array to store entries and LU decompostion to support linear system solution and inverse.

The LU decompostion is performed as needed, to support the following operations:

  • solve
  • isSingular
  • getDeterminant
  • inverse

Usage notes:

  • The LU decomposition is cached and reused on subsequent calls. If data are modified via references to the underlying array obtained using getDataRef(), then the stored LU decomposition will not be discarded. In this case, you need to explicitly invoke LUDecompose() to recompute the decomposition before using any of the methods above.
  • As specified in the RealMatrix interface, matrix element indexing is 0-based -- e.g., getEntry(0, 0) returns the element in the first row, first column of the matrix.

version:
   $Revision: 355770 $ $Date: 2005-12-10 12:48:57 -0700 (Sat, 10 Dec 2005) $


Field Summary
protected static  doubleTOO_SMALL
    

Constructor Summary
public  RealMatrixImpl()
    
public  RealMatrixImpl(int rowDimension, int columnDimension)
     Create a new RealMatrix with the supplied row and column dimensions.
public  RealMatrixImpl(double[][] d)
     Create a new RealMatrix using the input array as the underlying data array.
public  RealMatrixImpl(double[] v)
     Create a new (column) RealMatrix using v as the data for the unique column of the v.length x 1 matrix created.

Method Summary
public  RealMatrixadd(RealMatrix m)
     Compute the sum of this and m.
public  RealMatrixcopy()
     Create a new RealMatrix which is a copy of this.
public  booleanequals(Object object)
     Returns true iff object is a RealMatrixImpl instance with the same dimensions as this and all corresponding matrix entries are equal.
public  double[]getColumn(int col)
     Returns the entries in column number col as an array.

Column indices start at 0.

public  intgetColumnDimension()
    
public  RealMatrixgetColumnMatrix(int column)
     Returns the entries in column number column as a column matrix.
public  double[][]getData()
     Returns matrix entries as a two-dimensional array.
public  double[][]getDataRef()
     Returns a reference to the underlying data array.
public  doublegetDeterminant()
    
public  doublegetEntry(int row, int column)
     Returns the entry in the specified row and column.
protected  RealMatrixgetIdentity(int dimension)
     Returns dimension x dimension identity matrix.
protected  RealMatrixgetLUMatrix()
     Returns the LU decomposition as a RealMatrix.
public  doublegetNorm()
    
protected  int[]getPermutation()
     Returns the permutation associated with the lu decomposition. The entries of the array represent a permutation of the numbers 0, ...
public  double[]getRow(int row)
     Returns the entries in row number row as an array.

Row indices start at 0.

public  intgetRowDimension()
    
public  RealMatrixgetRowMatrix(int row)
     Returns the entries in row number row as a row matrix.
public  RealMatrixgetSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
     Gets a submatrix.
public  RealMatrixgetSubMatrix(int[] selectedRows, int[] selectedColumns)
     Gets a submatrix.
public  doublegetTrace()
    
public  inthashCode()
     Computes a hashcode for the matrix.
public  RealMatrixinverse()
     Returns the inverse matrix if this matrix is invertible.
public  booleanisSingular()
    
public  booleanisSquare()
    
public  voidluDecompose()
     Computes a new LU decompostion for this matrix, storing the result for use by other methods.

Implementation Note:
Uses Crout's algortithm, with partial pivoting.

Usage Note:
This method should rarely be invoked directly.

public  RealMatrixmultiply(RealMatrix m)
     Returns the result of postmultiplying this by m.
public  double[]operate(double[] v)
    
public  RealMatrixpreMultiply(RealMatrix m)
     Returns the result premultiplying this by m.
public  double[]preMultiply(double[] v)
    
public  RealMatrixscalarAdd(double d)
     Returns the result of adding d to each entry of this.
public  RealMatrixscalarMultiply(double d)
    
public  voidsetSubMatrix(double[][] subMatrix, int row, int column)
     Replace the submatrix starting at row, column using data in the input subMatrix array.
public  double[]solve(double[] b)
     Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns of b.
public  RealMatrixsolve(RealMatrix b)
     Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns of b.
public  RealMatrixsubtract(RealMatrix m)
     Compute this minus m.
public  StringtoString()
    
public  RealMatrixtranspose()
     Returns the transpose matrix.

Field Detail
TOO_SMALL
protected static double TOO_SMALL(Code)
Bound to determine effective singularity in LU decomposition




Constructor Detail
RealMatrixImpl
public RealMatrixImpl()(Code)
Creates a matrix with no data



RealMatrixImpl
public RealMatrixImpl(int rowDimension, int columnDimension)(Code)
Create a new RealMatrix with the supplied row and column dimensions.
Parameters:
  rowDimension - the number of rows in the new matrix
Parameters:
  columnDimension - the number of columns in the new matrix
throws:
  IllegalArgumentException - if row or column dimension is notpositive



RealMatrixImpl
public RealMatrixImpl(double[][] d)(Code)
Create a new RealMatrix using the input array as the underlying data array.

The input array is copied, not referenced.
Parameters:
  d - data for new matrix
throws:
  IllegalArgumentException - if data is not rectangular(not all rows have the same length) or empty
throws:
  NullPointerException - if data is null




RealMatrixImpl
public RealMatrixImpl(double[] v)(Code)
Create a new (column) RealMatrix using v as the data for the unique column of the v.length x 1 matrix created.

The input array is copied, not referenced.
Parameters:
  v - column vector holding data for new matrix





Method Detail
add
public RealMatrix add(RealMatrix m) throws IllegalArgumentException(Code)
Compute the sum of this and m.
Parameters:
  m - matrix to be added this + m
throws:
  IllegalArgumentException - if m is not the same size as this



copy
public RealMatrix copy()(Code)
Create a new RealMatrix which is a copy of this. the cloned matrix



equals
public boolean equals(Object object)(Code)
Returns true iff object is a RealMatrixImpl instance with the same dimensions as this and all corresponding matrix entries are equal. Corresponding entries are compared using java.lang.Double.doubleToLongBits(double)
Parameters:
  object - the object to test equality against. true if object equals this



getColumn
public double[] getColumn(int col) throws MatrixIndexException(Code)
Returns the entries in column number col as an array.

Column indices start at 0. A MatrixIndexException is thrown unless 0 <= column < columnDimension.
Parameters:
  col - the column to be fetched array of entries in the column
throws:
  MatrixIndexException - if the specified column index is not valid




getColumnDimension
public int getColumnDimension()(Code)
columnDimension



getColumnMatrix
public RealMatrix getColumnMatrix(int column) throws MatrixIndexException(Code)
Returns the entries in column number column as a column matrix. Column indices start at 0.
Parameters:
  column - the column to be fetched column matrix
throws:
  MatrixIndexException - if the specified column index is invalid



getData
public double[][] getData()(Code)
Returns matrix entries as a two-dimensional array.

Makes a fresh copy of the underlying data. 2-dimensional array of entries




getDataRef
public double[][] getDataRef()(Code)
Returns a reference to the underlying data array.

Does not make a fresh copy of the underlying data. 2-dimensional array of entries




getDeterminant
public double getDeterminant() throws InvalidMatrixException(Code)
determinant
throws:
  InvalidMatrixException - if matrix is not square



getEntry
public double getEntry(int row, int column) throws MatrixIndexException(Code)
Returns the entry in the specified row and column.

Row and column indices start at 0 and must satisfy

  • 0 <= row < rowDimension
  • 0 <= column < columnDimension
otherwise a MatrixIndexException is thrown.
Parameters:
  row - row location of entry to be fetched
Parameters:
  column - column location of entry to be fetched matrix entry in row,column
throws:
  MatrixIndexException - if the row or column index is not valid



getIdentity
protected RealMatrix getIdentity(int dimension)(Code)
Returns dimension x dimension identity matrix.
Parameters:
  dimension - dimension of identity matrix to generate identity matrix
throws:
  IllegalArgumentException - if dimension is not positiveMatrixUtils.createRealIdentityMatrix



getLUMatrix
protected RealMatrix getLUMatrix() throws InvalidMatrixException(Code)
Returns the LU decomposition as a RealMatrix. Returns a fresh copy of the cached LU matrix if this has been computed; otherwise the composition is computed and cached for use by other methods. Since a copy is returned in either case, changes to the returned matrix do not affect the LU decomposition property.

The matrix returned is a compact representation of the LU decomposition. Elements below the main diagonal correspond to entries of the "L" matrix; elements on and above the main diagonal correspond to entries of the "U" matrix.

Example:

 Returned matrix                L                  U
 2  3  1                   1  0  0            2  3  1
 5  4  6                   5  1  0            0  4  6
 1  7  8                   1  7  1            0  0  8
 
The L and U matrices satisfy the matrix equation LU = permuteRows(this),
where permuteRows reorders the rows of the matrix to follow the order determined by the permutation property. LU decomposition matrix
throws:
  InvalidMatrixException - if the matrix is non-square or singular.



getNorm
public double getNorm()(Code)
norm



getPermutation
protected int[] getPermutation()(Code)
Returns the permutation associated with the lu decomposition. The entries of the array represent a permutation of the numbers 0, ... , nRows - 1.

Example: permutation = [1, 2, 0] means current 2nd row is first, current third row is second and current first row is last.

Returns a fresh copy of the array. the permutation




getRow
public double[] getRow(int row) throws MatrixIndexException(Code)
Returns the entries in row number row as an array.

Row indices start at 0. A MatrixIndexException is thrown unless 0 <= row < rowDimension.
Parameters:
  row - the row to be fetched array of entries in the row
throws:
  MatrixIndexException - if the specified row index is not valid




getRowDimension
public int getRowDimension()(Code)
rowDimension



getRowMatrix
public RealMatrix getRowMatrix(int row) throws MatrixIndexException(Code)
Returns the entries in row number row as a row matrix. Row indices start at 0.
Parameters:
  row - the row to be fetched row matrix
throws:
  MatrixIndexException - if the specified row index is invalid



getSubMatrix
public RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn) throws MatrixIndexException(Code)
Gets a submatrix. Rows and columns are indicated counting from 0 to n-1.
Parameters:
  startRow - Initial row index
Parameters:
  endRow - Final row index
Parameters:
  startColumn - Initial column index
Parameters:
  endColumn - Final column index The subMatrix containing the data of thespecified rows and columns
exception:
  MatrixIndexException - if row or column selections are not valid



getSubMatrix
public RealMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns) throws MatrixIndexException(Code)
Gets a submatrix. Rows and columns are indicated counting from 0 to n-1.
Parameters:
  selectedRows - Array of row indices must be non-empty
Parameters:
  selectedColumns - Array of column indices must be non-empty The subMatrix containing the data in thespecified rows and columns
exception:
  MatrixIndexException - if supplied row or column index arraysare not valid



getTrace
public double getTrace() throws IllegalArgumentException(Code)
trace
throws:
  IllegalArgumentException - if the matrix is not square



hashCode
public int hashCode()(Code)
Computes a hashcode for the matrix. hashcode for matrix



inverse
public RealMatrix inverse() throws InvalidMatrixException(Code)
Returns the inverse matrix if this matrix is invertible. inverse matrix
throws:
  InvalidMatrixException - if this is not invertible



isSingular
public boolean isSingular()(Code)
true if the matrix is singular



isSquare
public boolean isSquare()(Code)
true if the matrix is square (rowDimension = columnDimension)



luDecompose
public void luDecompose() throws InvalidMatrixException(Code)
Computes a new LU decompostion for this matrix, storing the result for use by other methods.

Implementation Note:
Uses Crout's algortithm, with partial pivoting.

Usage Note:
This method should rarely be invoked directly. Its only use is to force recomputation of the LU decomposition when changes have been made to the underlying data using direct array references. Changes made using setXxx methods will trigger recomputation when needed automatically.
throws:
  InvalidMatrixException - if the matrix is non-square or singular.




multiply
public RealMatrix multiply(RealMatrix m) throws IllegalArgumentException(Code)
Returns the result of postmultiplying this by m.
Parameters:
  m - matrix to postmultiply by this*m
throws:
  IllegalArgumentException - if columnDimension(this) != rowDimension(m)



operate
public double[] operate(double[] v) throws IllegalArgumentException(Code)

Parameters:
  v - vector to operate on
throws:
  IllegalArgumentException - if columnDimension != v.length resulting vector



preMultiply
public RealMatrix preMultiply(RealMatrix m) throws IllegalArgumentException(Code)
Returns the result premultiplying this by m.
Parameters:
  m - matrix to premultiply by m * this
throws:
  IllegalArgumentException - if rowDimension(this) != columnDimension(m)



preMultiply
public double[] preMultiply(double[] v) throws IllegalArgumentException(Code)

Parameters:
  v - vector to premultiply by
throws:
  IllegalArgumentException - if rowDimension != v.length resulting matrix



scalarAdd
public RealMatrix scalarAdd(double d)(Code)
Returns the result of adding d to each entry of this.
Parameters:
  d - value to be added to each entry d + this



scalarMultiply
public RealMatrix scalarMultiply(double d)(Code)
Returns the result multiplying each entry of this by d
Parameters:
  d - value to multiply all entries by d * this



setSubMatrix
public void setSubMatrix(double[][] subMatrix, int row, int column) throws MatrixIndexException(Code)
Replace the submatrix starting at row, column using data in the input subMatrix array. Indexes are 0-based.

Example:
Starting with

 1  2  3  4
 5  6  7  8
 9  0  1  2
 
and subMatrix = {{3, 4} {5,6}}, invoking setSubMatrix(subMatrix,1,1)) will result in
 1  2  3  4
 5  3  4  8
 9  5  6  2
 

Parameters:
  subMatrix - array containing the submatrix replacement data
Parameters:
  row - row coordinate of the top, left element to be replaced
Parameters:
  column - column coordinate of the top, left element to be replaced
throws:
  MatrixIndexException - if subMatrix does not fit into this matrix from element in (row, column)
throws:
  IllegalArgumentException - if subMatrix is not rectangular(not all rows have the same length) or empty
throws:
  NullPointerException - if subMatrix is null
since:
   1.1



solve
public double[] solve(double[] b) throws IllegalArgumentException, InvalidMatrixException(Code)
Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns of b.
Parameters:
  b - array of constant forming RHS of linear systems toto solve solution array
throws:
  IllegalArgumentException - if this.rowDimension != row dimension
throws:
  InvalidMatrixException - if this matrix is not square or is singular



solve
public RealMatrix solve(RealMatrix b) throws IllegalArgumentException, InvalidMatrixException(Code)
Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns of b.
Parameters:
  b - matrix of constant vectors forming RHS of linear systems toto solve matrix of solution vectors
throws:
  IllegalArgumentException - if this.rowDimension != row dimension
throws:
  InvalidMatrixException - if this matrix is not square or is singular



subtract
public RealMatrix subtract(RealMatrix m) throws IllegalArgumentException(Code)
Compute this minus m.
Parameters:
  m - matrix to be subtracted this + m
throws:
  IllegalArgumentException - if m is not the same size as *this



toString
public String toString()(Code)

See Also:   java.lang.Object.toString



transpose
public RealMatrix transpose()(Code)
Returns the transpose matrix. transpose matrix



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.