/// <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.EnumerateNonZeroIndexed()) { result.At(element.Item1, column, element.Item2); } } return(iterator.Status); }