/// <summary> /// Solves the matrix equation AX = B, where A is the coefficient matrix (this matrix), B is the solution matrix and X is the unknown matrix. /// </summary> /// <param name="input">The solution matrix <c>B</c>.</param> /// <param name="result">The result matrix <c>X</c></param> /// <param name="solver">The iterative solver to use.</param> /// <param name="iterator">The iterator to use to control when to stop iterating.</param> /// <param name="preconditioner">The preconditioner to use for approximations.</param> public IterationStatus TrySolveIterative(Matrix <T> input, Matrix <T> result, IIterativeSolver <T> solver, Iterator <T> iterator = null, IPreconditioner <T> preconditioner = null) { if (RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { throw DimensionsDontMatch <ArgumentException>(this, input, result); } if (iterator == null) { iterator = new Iterator <T>(Build.IterativeSolverStopCriteria()); } if (preconditioner == null) { preconditioner = new UnitPreconditioner <T>(); } for (var column = 0; column < input.ColumnCount; column++) { var solution = Vector <T> .Build.Dense(RowCount); solver.Solve(this, input.Column(column), solution, iterator, preconditioner); foreach (var element in solution.EnumerateIndexed(Zeros.AllowSkip)) { result.At(element.Item1, column, element.Item2); } } return(iterator.Status); }
// Iterative Solvers: Full /// <summary> /// Solves the matrix equation Ax = b, where A is the coefficient matrix (this matrix), b is the solution vector and x is the unknown vector. /// </summary> /// <param name="input">The solution vector <c>b</c>.</param> /// <param name="result">The result vector <c>x</c>.</param> /// <param name="solver">The iterative solver to use.</param> /// <param name="iterator">The iterator to use to control when to stop iterating.</param> /// <param name="preconditioner">The preconditioner to use for approximations.</param> public IterationStatus TrySolveIterative(Vector <T> input, Vector <T> result, IIterativeSolver <T> solver, Iterator <T> iterator = null, IPreconditioner <T> preconditioner = null) { if (iterator == null) { iterator = new Iterator <T>(Build.IterativeSolverStopCriteria()); } if (preconditioner == null) { preconditioner = new UnitPreconditioner <T>(); } solver.Solve(this, input, result, iterator, preconditioner); return(iterator.Status); }