From cb58405b853388f0a1923dd10225fcfe054af3a1 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Tue, 17 Sep 2013 21:55:55 +0200 Subject: [PATCH] LA: add direct (factorization-based) Solve methods to matrix type --- src/Numerics/LinearAlgebra/Matrix.Solve.cs | 69 +++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/src/Numerics/LinearAlgebra/Matrix.Solve.cs b/src/Numerics/LinearAlgebra/Matrix.Solve.cs index c41994ab..70ad8a2c 100644 --- a/src/Numerics/LinearAlgebra/Matrix.Solve.cs +++ b/src/Numerics/LinearAlgebra/Matrix.Solve.cs @@ -81,7 +81,73 @@ namespace MathNet.Numerics.LinearAlgebra public abstract Evd Evd(); - // Iterative Solvers: Try + + // Direct Solvers: Full + + /// + /// Solves a system of linear equations, Ax = b, with A QR factorized. + /// + /// The right hand side vector, b. + /// The left hand side , x. + public void Solve(Vector input, Vector result) + { + if (ColumnCount == RowCount) + { + LU().Solve(input, result); + return; + } + + QR().Solve(input, result); + } + + /// + /// Solves a system of linear equations, AX = B, with A QR factorized. + /// + /// The right hand side , B. + /// The left hand side , X. + public void Solve(Matrix input, Matrix result) + { + if (ColumnCount == RowCount) + { + LU().Solve(input, result); + return; + } + + QR().Solve(input, result); + } + + + + // Direct Solvers: Simple + + /// + /// Solves a system of linear equations, AX = B, with A QR factorized. + /// + /// The right hand side , B. + /// The left hand side , X. + public Matrix Solve(Matrix input) + { + var matrixX = CreateMatrix(ColumnCount, input.ColumnCount); + Solve(input, matrixX); + return matrixX; + } + + + /// + /// Solves a system of linear equations, Ax = b, with A QR factorized. + /// + /// The right hand side vector, b. + /// The left hand side , x. + public Vector Solve(Vector input) + { + var x = CreateVector(ColumnCount); + Solve(input, x); + return x; + } + + + + // Iterative Solvers: Full /// /// 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. @@ -197,6 +263,7 @@ namespace MathNet.Numerics.LinearAlgebra } + // Iterative Solvers: Simple public Vector SolveIterative(Vector input, IIterativeSolver solver, IPreconditioner preconditioner, Iterator iterator)