/// <summary> /// Solves an N by N system of equations, with right-hand N-vecctor. /// </summary> /// <param name="coeffs">Must be a square matrix</param> /// <param name="rhs">Right hand side</param> /// <param name="scheme">Indicates the scheme used to solve the system</param> /// <param name="suppress_determinant_validation">Used to supress determinant validation, lower computing time, but risks error</param> /// <returns></returns> public static Matrix solve_system(Matrix coeffs, Matrix rhs, SystemSolvingScheme scheme, bool suppress_determinant_validation, bool enable_console_output) { if (!coeffs.IsSquare || (rhs.Columns != 1) || (rhs.Rows != coeffs.Rows)) { throw new ArgumentException("System has incompatible dimensions."); } if (!suppress_determinant_validation) { if (coeffs.isSingular) { throw new ArgumentException("Coefficient matrix is singular."); } } switch (scheme) { case SystemSolvingScheme.Basic: { return(coeffs.Inverse * rhs); } case SystemSolvingScheme.SortToDiagonal: { return(solve_using_sort_diagonal(coeffs, rhs, true)); } case SystemSolvingScheme.Kaczmarz: { return(kaczmarz_solve(coeffs, rhs, 100, 1E-5)); } default: { throw new ArgumentException("Invalid scheme"); } } }
/// <summary> /// Solves an N by N system of equations, with right-hand N-vecctor. /// </summary> /// <param name="coeffs">Must be a square matrix</param> /// <param name="rhs">Right hand side</param> /// <param name="scheme">Indicates the scheme used to solve the system</param> /// <returns></returns> public static Matrix solve_system(Matrix coeffs, Matrix rhs, SystemSolvingScheme scheme) { return(solve_system(coeffs, rhs, scheme, true, false)); }