public class Matrix extends Object implements Cloneable, Serializable, ICacheAble
double[][] vals = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}};
Matrix A = new Matrix(vals);
Matrix b = Matrix.random(3,1);
Matrix x = A.solve(b);
Matrix r = A.times(x).minus(b);
double rnorm = r.normInf();
| 构造器和说明 |
|---|
Matrix() |
Matrix(double[][] A)
Construct a matrix from a 2-D array.
|
Matrix(double[][] A,
int m,
int n)
Construct a matrix quickly without checking arguments.
|
Matrix(double[] vals,
int m)
Construct a matrix from a one-dimensional packed array
|
Matrix(int m,
int n)
Construct an m-by-n matrix of zeros.
|
Matrix(int m,
int n,
double s)
Construct an m-by-n constant matrix.
|
| 限定符和类型 | 方法和说明 |
|---|---|
Matrix |
arrayLeftDivide(Matrix B)
Element-by-element left division, C = A.
|
Matrix |
arrayLeftDivideEquals(Matrix B)
Element-by-element left division in place, A = A.
|
Matrix |
arrayRightDivide(Matrix B)
Element-by-element right division, C = A.
|
Matrix |
arrayRightDivideEquals(Matrix B)
Element-by-element right division in place, A = A.
|
Matrix |
arrayTimes(Matrix B)
Element-by-element multiplication, C = A.
|
Matrix |
arrayTimesEquals(Matrix B)
Element-by-element multiplication in place, A = A.
|
Matrix |
block(int i,
int j,
int p,
int q) |
Object |
clone()
Clone the Matrix object.
|
Matrix |
col(int j)
取出第j列作为一个列向量
|
int |
cols() |
static Matrix |
constructWithCopy(double[][] A)
Construct a matrix from a copy of a 2-D array.
|
Matrix |
copy()
Make a deep copy of a matrix
|
double[][] |
cube()
返回矩阵的立方(以数组形式)
|
double |
get(int i,
int j)
Get a single element.
|
double[][] |
getArray()
Access the internal two-dimensional array.
|
double[][] |
getArrayCopy()
Copy the internal two-dimensional array.
|
int |
getColumnDimension()
Get column dimension.
|
double[] |
getColumnPackedCopy()
Make a one-dimensional column packed copy of the internal array.
|
Matrix |
getMatrix(int[] r,
int[] c)
Get a submatrix.
|
Matrix |
getMatrix(int[] r,
int j0,
int j1)
Get a submatrix.
|
Matrix |
getMatrix(int i0,
int i1,
int[] c)
Get a submatrix.
|
Matrix |
getMatrix(int i0,
int i1,
int j0,
int j1)
Get a submatrix.
|
int |
getRowDimension()
Get row dimension.
|
double[] |
getRowPackedCopy()
Make a one-dimensional row packed copy of the internal array.
|
static Matrix |
identity(int m,
int n)
Generate identity matrix
|
boolean |
load(ByteArray byteArray)
载入
|
Matrix |
minus(Matrix B)
C = A - B
|
Matrix |
minusEquals(Matrix B)
A = A - B
|
double |
norm1()
One norm
|
double |
normInf()
Infinity norm
|
Matrix |
plus(Matrix B)
C = A + B
|
Matrix |
plusEquals(Matrix B)
A = A + B
|
void |
print(int w,
int d)
Print the matrix to stdout.
|
void |
print(NumberFormat format,
int width)
Print the matrix to stdout.
|
void |
print(PrintWriter output,
int w,
int d)
Print the matrix to the output stream.
|
void |
print(PrintWriter output,
NumberFormat format,
int width)
Print the matrix to the output stream.
|
static Matrix |
random(int m,
int n)
Generate matrix with random elements
|
static Matrix |
read(BufferedReader input)
Read a matrix from a stream.
|
Matrix |
row(int i)
取出第i行作为一个行向量
|
int |
rows() |
void |
save(DataOutputStream out)
写入
|
void |
set(int i,
int j,
double s)
Set a single element.
|
void |
setMatrix(int[] r,
int[] c,
Matrix X)
Set a submatrix.
|
void |
setMatrix(int[] r,
int j0,
int j1,
Matrix X)
Set a submatrix.
|
void |
setMatrix(int i0,
int i1,
int[] c,
Matrix X)
Set a submatrix.
|
void |
setMatrix(int i0,
int i1,
int j0,
int j1,
Matrix X)
Set a submatrix.
|
void |
setZero() |
Matrix |
times(double s)
Multiply a matrix by a scalar, C = s*A
|
Matrix |
times(Matrix B)
Linear algebraic matrix multiplication, A * B
|
Matrix |
timesEquals(double s)
Multiply a matrix by a scalar in place, A = s*A
|
double |
trace()
Matrix trace.
|
Matrix |
transpose()
Matrix transpose.
|
Matrix |
uminus()
Unary minus
|
static Matrix |
zero(int m,
int n) |
public Matrix(int m,
int n)
m - Number of rows.n - Number of colums.public Matrix(int m,
int n,
double s)
m - Number of rows.n - Number of colums.s - Fill the matrix with this scalar value.public Matrix(double[][] A)
A - Two-dimensional array of doubles.IllegalArgumentException - All rows must have the same lengthconstructWithCopy(double[][])public Matrix(double[][] A,
int m,
int n)
A - Two-dimensional array of doubles.m - Number of rows.n - Number of colums.public Matrix(double[] vals,
int m)
vals - One-dimensional array of doubles, packed by columns (ala Fortran).m - Number of rows.IllegalArgumentException - Array length must be a multiple of m.public Matrix()
public static Matrix constructWithCopy(double[][] A)
A - Two-dimensional array of doubles.IllegalArgumentException - All rows must have the same lengthpublic Matrix copy()
public double[][] getArray()
public double[][] getArrayCopy()
public double[] getColumnPackedCopy()
public double[] getRowPackedCopy()
public int getRowDimension()
public int getColumnDimension()
public double get(int i,
int j)
i - Row index.j - Column index.ArrayIndexOutOfBoundsExceptionpublic Matrix getMatrix(int i0, int i1, int j0, int j1)
i0 - Initial row indexi1 - Final row indexj0 - Initial column indexj1 - Final column indexArrayIndexOutOfBoundsException - Submatrix indicespublic Matrix getMatrix(int[] r, int[] c)
r - Array of row indices.c - Array of column indices.ArrayIndexOutOfBoundsException - Submatrix indicespublic Matrix getMatrix(int i0, int i1, int[] c)
i0 - Initial row indexi1 - Final row indexc - Array of column indices.ArrayIndexOutOfBoundsException - Submatrix indicespublic Matrix getMatrix(int[] r, int j0, int j1)
r - Array of row indices.j0 - Initial column indexj1 - Final column indexArrayIndexOutOfBoundsException - Submatrix indicespublic void set(int i,
int j,
double s)
i - Row index.j - Column index.s - A(i,j).ArrayIndexOutOfBoundsExceptionpublic void setMatrix(int i0,
int i1,
int j0,
int j1,
Matrix X)
i0 - Initial row indexi1 - Final row indexj0 - Initial column indexj1 - Final column indexX - A(i0:i1,j0:j1)ArrayIndexOutOfBoundsException - Submatrix indicespublic void setMatrix(int[] r,
int[] c,
Matrix X)
r - Array of row indices.c - Array of column indices.X - A(r(:),c(:))ArrayIndexOutOfBoundsException - Submatrix indicespublic void setMatrix(int[] r,
int j0,
int j1,
Matrix X)
r - Array of row indices.j0 - Initial column indexj1 - Final column indexX - A(r(:),j0:j1)ArrayIndexOutOfBoundsException - Submatrix indicespublic void setMatrix(int i0,
int i1,
int[] c,
Matrix X)
i0 - Initial row indexi1 - Final row indexc - Array of column indices.X - A(i0:i1,c(:))ArrayIndexOutOfBoundsException - Submatrix indicespublic Matrix transpose()
public double norm1()
public double normInf()
public Matrix uminus()
public Matrix arrayTimes(Matrix B)
B - another matrixpublic Matrix arrayTimesEquals(Matrix B)
B - another matrixpublic Matrix arrayRightDivide(Matrix B)
B - another matrixpublic Matrix arrayRightDivideEquals(Matrix B)
B - another matrixpublic Matrix arrayLeftDivide(Matrix B)
B - another matrixpublic Matrix arrayLeftDivideEquals(Matrix B)
B - another matrixpublic Matrix times(double s)
s - scalarpublic Matrix timesEquals(double s)
s - scalarpublic Matrix times(Matrix B)
B - another matrixIllegalArgumentException - Matrix inner dimensions must agree.public double trace()
public static Matrix random(int m, int n)
m - Number of rows.n - Number of colums.public static Matrix identity(int m, int n)
m - Number of rows.n - Number of colums.public void print(int w,
int d)
w - Column width.d - Number of digits after the decimal.public void print(PrintWriter output, int w, int d)
output - Output stream.w - Column width.d - Number of digits after the decimal.public void print(NumberFormat format, int width)
format - A Formatting object for individual elements.width - Field width for each column.DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)public void print(PrintWriter output, NumberFormat format, int width)
output - the output stream.format - A formatting object to format the matrix elementswidth - Column width.DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)public static Matrix read(BufferedReader input) throws IOException
input - the input stream.IOExceptionpublic static Matrix zero(int m, int n)
public int rows()
public int cols()
public Matrix col(int j)
j - public Matrix row(int i)
i - public Matrix block(int i, int j, int p, int q)
public double[][] cube()
public void setZero()
public void save(DataOutputStream out) throws Exception
ICacheAblesave 在接口中 ICacheAbleExceptionpublic boolean load(ByteArray byteArray)
ICacheAbleload 在接口中 ICacheAbleCopyright © 2014–2017 码农场. All rights reserved.