static private Forward ( Matrix A, |
||
A | Matrix | Input Matrix. |
b | The Vector to process. | |
return |
/// <summary> /// Solves Ax = b for x If A is not square or the system is overdetermined, this operation solves /// the linear least squares A.T * A x = A.T * b. /// </summary> /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception> /// <param name="A">Matrix A.</param> /// <param name="b">Vector b.</param> /// <returns>x.</returns> public static Vector operator /(Matrix A, Vector b) { if (A.Rows != b.Length) { throw new InvalidOperationException("Matrix row count does not match vector length!"); } // LLS if (A.Rows != A.Cols) { Matrix C = A.T * A; Matrix L = C.Cholesky(); Vector d = (A.T * b).ToVector(); Vector z = Matrix.Forward(L, d); Vector x = Matrix.Backward(L.T, z); return(x); } // regular solve else { // need to be smarter here.... return(((A ^ -1) * b).ToVector()); } }