public MatrixValue Function(MatrixValue M) { var lu = new LUDecomposition(M); return lu.U; }
/// <summary> /// Computes the determinant of the matrix. /// </summary> /// <returns>The value of the determinant.</returns> public ScalarValue Det() { if (DimensionX == DimensionY) { var n = DimensionX; if (n == 1) { return this[1, 1]; } else if (n == 2) { return this[1, 1] * this[2, 2] - this[1, 2] * this[2, 1]; } else if (n == 3) { return this[1, 1] * (this[2, 2] * this[3, 3] - this[2, 3] * this[3, 2]) + this[1, 2] * (this[2, 3] * this[3, 1] - this[2, 1] * this[3, 3]) + this[1, 3] * (this[2, 1] * this[3, 2] - this[2, 2] * this[3, 1]); } else if (n == 4) { //I guess that's right return this[1, 1] * (this[2, 2] * (this[3, 3] * this[4, 4] - this[3, 4] * this[4, 3]) + this[2, 3] * (this[3, 4] * this[4, 2] - this[3, 2] * this[4, 4]) + this[2, 4] * (this[3, 2] * this[4, 3] - this[3, 3] * this[4, 2])) - this[1, 2] * (this[2, 1] * (this[3, 3] * this[4, 4] - this[3, 4] * this[4, 3]) + this[2, 3] * (this[3, 4] * this[4, 1] - this[3, 1] * this[4, 4]) + this[2, 4] * (this[3, 1] * this[4, 3] - this[3, 3] * this[4, 1])) + this[1, 3] * (this[2, 1] * (this[3, 2] * this[4, 4] - this[3, 4] * this[4, 2]) + this[2, 2] * (this[3, 4] * this[4, 1] - this[3, 1] * this[4, 4]) + this[2, 4] * (this[3, 1] * this[4, 2] - this[3, 2] * this[4, 1])) - this[1, 4] * (this[2, 1] * (this[3, 2] * this[4, 3] - this[3, 3] * this[4, 2]) + this[2, 2] * (this[3, 3] * this[4, 1] - this[3, 1] * this[4, 3]) + this[2, 3] * (this[3, 1] * this[4, 2] - this[3, 2] * this[4, 1])); } var lu = new LUDecomposition(this); return lu.Determinant(); } return ScalarValue.Zero; }
/// <summary> /// Computes the inverse (if it exists). /// </summary> /// <returns>The inverse matrix.</returns> public MatrixValue Inverse() { var target = One(DimensionX); if (DimensionX < 24) { var lu = new YAMP.Numerics.LUDecomposition(this); return lu.Solve(target); } else if (IsSymmetric) { var cho = new YAMP.Numerics.CholeskyDecomposition(this); return cho.Solve(target); } var qr = YAMP.Numerics.QRDecomposition.Create(this); return qr.Solve(target); }
public ArgumentsValue Function(MatrixValue M) { var lu = new LUDecomposition(M); return new ArgumentsValue(lu.L, lu.U, lu.Pivot); }