/// <summary> /// /// </summary> /// <param name="b"></param> /// <returns></returns> public DoubleMatrix CrossProduct(DoubleMatrix b) { throw new NotImplementedException(); //return DoubleMatrix.CrossProduct(this, b); }
/// <summary> /// /// </summary> /// <param name="b"></param> /// <returns></returns> public Double DotProduct(DoubleMatrix b) { return(DoubleMatrix.DotProduct(this, b)); }
/// <summary> /// /// </summary> /// <param name="topMatrix"></param> /// <param name="bottomMatrix"></param> /// <returns></returns> public static DoubleMatrix JoinVertical(DoubleMatrix topMatrix, DoubleMatrix bottomMatrix) { return(DoubleMatrix.JoinVertical(new DoubleMatrix[] { topMatrix, bottomMatrix })); }
/// <summary>CopyFrom</summary> /// <param name="sourceMatrix"></param> public void CopyFrom(DoubleMatrix sourceMatrix) { this.InnerMatrix.CopyFrom(sourceMatrix.InnerMatrix, 0, 0); }
/// <summary>ScalarValue</summary> /// <param name="matrix"></param> /// <returns></returns> protected static Double ScalarValue(DoubleMatrix matrix) { return(matrix[0, 0]); }
/// <summary>Generates a new zero matrix</summary> /// <param name="rank">Rank of the matrix</param> /// <returns>Matrix of specified rank with all element values set to 0</returns> public static DoubleMatrix Zero(int rank) { return(DoubleMatrix.Zero(rank, rank)); }
public static DoubleMatrix operator *(DoubleMatrix matrix, double scalar) { return(DoubleMatrix.Multiplication(matrix, scalar)); }
/// <summary>Indicates whether the specified Matrix is null or is empty (of rank 0)</summary> /// <param name="matrix"></param> /// <returns>True if specified Matrix is null or empty (of rank == 0); false otherwise</returns> public static Boolean IsNullOrEmpty(DoubleMatrix matrix) { return(((object)matrix == null) || matrix.IsEmpty); }
public static DoubleMatrix operator -(DoubleMatrix matrix, double scalar) { return(DoubleMatrix.Subtraction(matrix, scalar)); }
public static DoubleMatrix operator *(DoubleMatrix matrix1, DoubleMatrix matrix2) { return(DoubleMatrix.Multiplication(matrix1, matrix2)); }
public static DoubleMatrix operator -(DoubleMatrix matrix1, DoubleMatrix matrix2) { return(DoubleMatrix.Subtraction(matrix1, matrix2)); }
public static DoubleMatrix operator +(double scalar, DoubleMatrix matrix) { return(DoubleMatrix.Addition(matrix, scalar)); }
/*****************************/ /* PUBLIC OPERATOR OVERLOADS */ /*****************************/ public static DoubleMatrix operator +(DoubleMatrix matrix1, DoubleMatrix matrix2) { return(DoubleMatrix.Addition(matrix1, matrix2)); }
/// <summary>ScalarValue</summary> /// <returns></returns> public Double ScalarValue() { return(DoubleMatrix.ScalarValue(this)); }
public static DoubleMatrix operator /(DoubleMatrix matrix, double scalar) { return(DoubleMatrix.Division(matrix, scalar)); }
/*************************/ /* PUBLIC STATIC METHODS */ /*************************/ /// <summary>Indicates whether the specified Matrix is null or is empty (of rank 0)</summary> /// <param name="matrix"></param> /// <returns>True if specified Matrix is null, false otherwise</returns> public static Boolean IsNull(DoubleMatrix matrix) { return((object)matrix == null); }
public static bool operator !=(DoubleMatrix matrix1, DoubleMatrix matrix2) { return(!DoubleMatrix.Equality(matrix1, matrix2)); }
/// <summary>Calculates the dot product (A . B) of two vectors</summary> /// <param name="vector1">First matrix (must be a row vector)</param> /// <param name="vector2">Second matrix (must be a column vector)</param> /// <returns>Returns the dot product of (matrix1 . matrix2)</returns> protected static Double DotProduct(DoubleMatrix vector1, DoubleMatrix vector2) { return(Multiplication(vector1, vector2.Transposed).ScalarValue()); }
/// <summary> /// /// </summary> /// <param name="matrix"></param> public DoubleMatrix(DoubleMatrix matrix) { _matrix = matrix.InnerMatrix.Clone(); }
/// <summary>Generates a new identity matrix</summary> /// <param name="rank">Rank of the matrix (width and height)</param> /// <returns>Matrix of specified rank with all diagonalOffset elements set to 1, and all others set to 0</returns> public static DoubleMatrix Identity(int rank) { return(DoubleMatrix.Identity(rank, rank)); }
/// <summary>CopyInto</summary> /// <param name="targetMatrix"></param> public void CopyInto(DoubleMatrix targetMatrix) { this.CopyInto(targetMatrix, 0, 0); }
/// <summary>Calculates the inverse of a square matrix by applying /// Gaussian Elimination techniques. For more information on /// algorithm see http://www.ecs.fullerton.edu/~mathews/numerical/mi.htm /// or your high school text book.</summary> /// <param name="matrix">Square matrix to be inverted</param> /// <returns>Inverse of input matrix</returns> protected static DoubleMatrix Invert(DoubleMatrix matrix) { if (!matrix.IsSquare) { throw new ArithmeticException("Cannot invert non-square matrix"); } // create an augmented matrix [A,I] with the input matrix I on the // left hand side and the identity matrix I on the right hand side // // [ 2 5 6 | 1 0 0 ] // eg [ 8 3 1 | 0 1 0 ] // [ 2 9 2 | 0 0 1 ] // DoubleMatrix augmentedMatrix = DoubleMatrix.JoinHorizontal(new DoubleMatrix[] { matrix, DoubleMatrix.Identity(matrix.ColumnCount, matrix.RowCount) }); for (int j1 = 0; j1 < augmentedMatrix.RowCount; j1++) { // check to see if any of the rows subsequent to i have a // higher absolute value on the current diagonalOffset (i,i). // if so, switch them to minimize rounding errors // // [ (2) 5 6 | 1 0 0 ] [ (8) 3 1 | 0 1 0 ] // eg [ 8 (3) 1 | 0 1 0 ] -> SWAP(R1, R2) -> [ 2 (5) 6 | 1 0 0 ] // [ 2 9 (2) | 0 0 1 ] [ 2 9 (2) | 0 0 1 ] // for (int j2 = j1 + 1; j2 < augmentedMatrix.RowCount; j2++) { if (Math.Abs(augmentedMatrix[j1, j2]) > Math.Abs(augmentedMatrix[j1, j1])) { //Console.WriteLine("Swap [" + j2 + "] with [" + i + "]"); augmentedMatrix.SwapRows(j1, j2); } } // normalize the row so the diagonalOffset value (i,i) is 1 // if (i,i) is 0, this row is null (we have > 0 nullity for this matrix) // // [ (8) 3 1 | 0 1 0 ] [ (1.0) 0.4 0.1 | 0.0 0.1 0.0 ] // eg [ 2 (5) 6 | 1 0 0 ] -> R1 = R1 / 8 -> [ 2.0 (5.0) 6.0 | 1.0 0.0 0.0 ] // [ 2 9 (2) | 0 0 1 ] [ 2.0 9.0 (2.0) | 0.0 0.0 1.0 ] //Console.WriteLine("Divide [" + i + "] by " + augmentedMatrix[i, i].ToString("0.00")); augmentedMatrix.Rows[j1].CopyFrom(augmentedMatrix.Rows[j1] / augmentedMatrix[j1, j1]); // look at each pair of rows {i, r} to see if r is linearly // dependent on i. if r does contain some factor of i vector, // subtract it out to make {i, r} linearly independent for (int j2 = 0; j2 < augmentedMatrix.RowCount; j2++) { if (j2 != j1) { //Console.WriteLine("Subtracting " + augmentedMatrix[i, j2].ToString("0.00") + " i [" + i + "] from [" + j2 + "]"); augmentedMatrix.Rows[j2].CopyFrom(new DoubleMatrix(augmentedMatrix.Rows[j2] - (augmentedMatrix[j1, j2] * augmentedMatrix.Rows[j1]))); } } } // separate the inverse from the right hand side of the augmented matrix // // [ (1) 0 0 | [ 2 5 6 ] // eg [ 0 (1) 0 | ~ [ 8 2 1 ] -> inverse // [ 0 0 (1) | [ 5 2 2 ] // DoubleMatrix inverse = augmentedMatrix.SubMatrix(new Int32Range(matrix.ColumnCount, matrix.ColumnCount + matrix.ColumnCount), new Int32Range(0, matrix.RowCount)); return(inverse); }
/// <summary> /// /// </summary> /// <param name="leftMatrix"></param> /// <param name="rightMatrix"></param> /// <returns></returns> public static DoubleMatrix JoinHorizontal(DoubleMatrix leftMatrix, DoubleMatrix rightMatrix) { return(DoubleMatrix.JoinHorizontal(new DoubleMatrix[] { leftMatrix, rightMatrix })); }