linear_problem module¶
Linear equations problem.
- class gemseo.algos.linear_solvers.linear_problem.LinearProblem(lhs, rhs=None, solution=None, is_symmetric=False, is_positive_def=False, is_converged=None)[source]¶
Bases:
object
Representation of the linear equations’ system
A.x = b
.It also contains the solution, and some properties of the system such as the symmetry or positive definiteness.
- Parameters
lhs (ndarray | spmatrix | LinearOperator) – The left-hand side (matrix or linear operator) of the problem.
rhs (ndarray | None) –
The right-hand side (vector) of the problem.
By default it is set to None.
solution (ndarray | None) –
The current solution.
By default it is set to None.
is_symmetric –
Whether to assume that the LHS is symmetric.
By default it is set to False.
is_positive_def –
Whether to assume that the LHS is positive definite.
By default it is set to False.
is_converged –
Whether the solution is converged to the specified tolerance. If False, the algorithm stopped before convergence. If None, no run was performed.
By default it is set to None.
- Return type
None
- check()[source]¶
Check the consistency of the dimensions of the LHS and RHS.
- Raises
ValueError – When the shapes are inconsistent.
- Return type
None
- compute_residuals(relative_residuals=True, store=False, current_x=None)[source]¶
Compute the L2 norm of the residuals of the problem.
- Parameters
relative_residuals –
If True, return norm(lhs.solution-rhs)/norm(rhs), else return norm(lhs.solution-rhs).
By default it is set to True.
store –
Whether to store the residuals value in the residuals_history attribute.
By default it is set to False.
current_x –
Compute the residuals associated with current_x, If None, compute then from the solution attribute.
By default it is set to None.
- Returns
The residuals value.
- Raises
ValueError – If self.solution is None and current_x is None.
- Return type
- plot_residuals()[source]¶
Plot the residuals’ convergence in log scale.
- Returns
The matplotlib figure.
- Raises
ValueError – When the residuals’ history is empty.
- Return type
- lhs: ndarray | LinearOperator | spmatrix¶
The left-hand side of the equation. If None, the problem can’t be solved and the user has to set it after init.
- rhs: ndarray¶
The right-hand side of the equation.
- solution: ndarray¶
The current solution of the problem.