[Home] DMelt member access. Java source code: flanagan.math.Matrix
/* Class Matrix
*
* Defines a matrix and includes the methods needed
* for standard matrix manipulations, e.g. multiplation,
* and related procedures, e.g. solution of linear
* simultaneous equations
*
* See class ComplexMatrix and PhasorMatrix for complex matrix arithmetic
*
* WRITTEN BY: Dr Michael Thomas Flanagan
*
* DATE: June 2002
* UPDATES: 21 April 2004, 16 February 2006, 31 March 2006, 22 April 2006,
* 1 July 2007, 17 July 2007, 18 August 2007, 7 October 2007
* 27 February 2008, 7 April 2008, 5 July 2008, 6-15 September 2008, 7-14 October 2008,
* 16 February 2009, 16 June 2009, 15 October 2009, 4-5 November 2009
* 12 January 2010, 19 February 2010, 14 November 2010
* 12 January 2011, 20 January 2011, 14-16 July 2011
* 7 April 2012, 26 June 2012
*
* DOCUMENTATION:
* See Michael Thomas Flanagan's Java library on-line web page:
* http://www.ee.ucl.ac.uk/~mflanaga/java/Matrix.html
* http://www.ee.ucl.ac.uk/~mflanaga/java/
*
* Copyright (c) 2002 - 2012 Michael Thomas Flanagan
* PERMISSION TO COPY:
*
* Permission to use, copy and modify this software and its documentation for NON-COMMERCIAL purposes is granted, without fee,
* provided that an acknowledgement to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies
* and associated documentation or publications.
*
* Redistributions of the source code of this source code, or parts of the source codes, must retain the above copyright notice, this list of conditions
* and the following disclaimer and requires written permission from the Michael Thomas Flanagan:
*
* Redistribution in binary form of all or parts of this class must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution and requires written permission from the Michael Thomas Flanagan:
*
* Dr Michael Thomas Flanagan makes no representations about the suitability or fitness of the software for any or for a particular purpose.
* Dr Michael Thomas Flanagan shall not be liable for any damages suffered as a result of using, modifying or distributing this software
* or its derivatives.
*
***************************************************************************************/
package flanagan.math;
import flanagan.analysis.Regression;
import flanagan.analysis.RegressionFunction;
import flanagan.math.ArrayMaths;
import flanagan.math.Conv;
import flanagan.analysis.Stat;
import java.util.ArrayList;
import java.util.Vector;
import java.math.BigDecimal;
import java.math.BigInteger;
public class Matrix{
private int numberOfRows = 0; // number of rows
private int numberOfColumns = 0; // number of columns
private double[][] matrix = null; // 2-D Matrix as double
private String[][] matrixS = null; // 2-D Matrix as String
private int entryType = -1; // Entry type
// = 0; double
// = 1; float
// = 2; long
// = 3; int
// = 4; BigDecimal
// = 5; BigInteger
// = x;
// = y;
private boolean numericalCheck = true; // = false if no numerical data entered, e.g. only non-numerical strings entered
private double[][] hessenberg = null; // 2-D Hessenberg equivalent
private boolean hessenbergDone = false; // = true when Hessenberg matrix calculated
private int permutationIndex[] = null; // row permutation index
private double rowSwapIndex = 1.0D; // row swap index
private double[] eigenValues = null; // eigen values of the matrix
private double[][] eigenVector = null; // eigen vectors of the matrix
private double[] sortedEigenValues = null; // eigen values of the matrix sorted into descending order
private double[][] sortedEigenVector = null; // eigen vectors of the matrix sorted to matching descending eigen value order
private int numberOfRotations = 0; // number of rotations in Jacobi transformation
private int[] eigenIndices = null; // indices of the eigen values before sorting into descending order
private int maximumJacobiIterations = 100; // maximum number of Jacobi iterations
private boolean eigenDone = false; // = true when eigen values and vectors calculated
private boolean matrixCheck = true; // check on matrix status
// true - no problems encountered in LU decomposition
// false - attempted a LU decomposition on a singular matrix
private boolean supressErrorMessage = false; // true - LU decompostion failure message supressed
private double tiny = 1.0e-100; // small number replacing zero in LU decomposition
// CONSTRUCTORS
// Construct a numberOfRows x numberOfColumns matrix of variables all equal to zero
public Matrix(int numberOfRows, int numberOfColumns){
this.numberOfRows = numberOfRows;
this.numberOfColumns = numberOfColumns;
this.matrix = new double[this.numberOfRows][this.numberOfColumns];
this.matrixS = new String[this.numberOfRows][this.numberOfColumns];
this.permutationIndex = new int[this.numberOfRows];
this.entryType = 0;
for(int i=0;i
public Matrix(ArrayList