squarematrix.java
来自「一个一元曲线多项式数值演示例子」· Java 代码 · 共 94 行
JAVA
94 行
package numbercruncher.matrix;
/**
* A square matrix.
*/
public class SquareMatrix
extends Matrix {
//--------------//
// Constructors //
//--------------//
/**
* Constructor.
* @param n the number of rows == the number of columns
*/
public SquareMatrix(int n) {
super(n, n);
}
/**
* Constructor.
* @param m the matrix (only the upper left square used)
*/
private SquareMatrix(Matrix m) {
set(m);
}
/**
* Constructor.
* @param values the array of values
*/
public SquareMatrix(float values[][]) {
set(values);
}
//---------//
// Setters //
//---------//
/**
* Set this square matrix from another matrix. Note that this
* matrix will reference the values of the argument matrix. If
* the values are not square, only the upper left square is used.
* @param values the 2-d array of values
*/
private void set(Matrix m) {
this.nRows = this.nCols = Math.min(m.nRows, m.nCols);
this.values = m.values;
}
/**
* Set this square matrix from a 2-d array of values. If the
* values are not square, only the upper left square is used.
* @param values the 2-d array of values
*/
protected void set(float values[][]) {
super.set(values);
nRows = nCols = Math.min(nRows, nCols);
}
//-------------------//
// Matrix operations //
//-------------------//
/**
* Add another square matrix to this matrix.
* @param sm the square matrix addend
* @return the sum matrix
* @throws numbercruncher.MatrixException for invalid size
*/
public SquareMatrix add(SquareMatrix sm) throws MatrixException {
return new SquareMatrix(super.add(sm));
}
/**
* Subtract another square matrix from this matrix.
* @param sm the square matrix subrrahend
* @return the difference matrix
* @throws numbercruncher.MatrixException for invalid size
*/
public SquareMatrix subtract(SquareMatrix sm) throws MatrixException {
return new SquareMatrix(super.subtract(sm));
}
/**
* Multiply this square matrix by another square matrix.
* @param sm the square matrix multiplier
* @return the product matrix
* @throws numbercruncher.MatrixException for invalid size
*/
public SquareMatrix multiply(SquareMatrix sm) throws MatrixException {
return new SquareMatrix(super.multiply(sm));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?