2
$\begingroup$

How can I solve a linear system of equations and get the general solution? Let $A$ be $m \times n$ and $b \in C(A)$. How do I get the general solution of $Ax=b$?

Example:

Let $A= \begin{bmatrix}1&0\\0&0 \end{bmatrix}$ and $b = \begin{bmatrix}1\\0 \end{bmatrix}$. The general solution of $Ax=b$ is $x=\begin{bmatrix}1\\0 \end{bmatrix} + t \begin{bmatrix}0\\1 \end{bmatrix}$.

If I use LinearSolve I only get the particular solution {1,0}.

A = {{1, 0}, {0, 0}}; b = {1, 0}; LinearSolve[A, b] // MatrixForm

This seems like a basic thing to do, solving linear systems of equations. Yet I searched Google and the forum and I didn't find a general answer to this problem. I read the documentation on LinearSolve and it says it gives only one solution. Is there no function in Mathematica that gives the general solution?

$\endgroup$
  • 2
    $\begingroup$ This will give a form of parametrized solution set: xx = Array[x,2];Solve[A.xx==b,xx] $\endgroup$ – Daniel Lichtblau Apr 11 '18 at 13:39
2
$\begingroup$

Maybe this way:

A = {{1, 0}, {0, 0}};
b = {1, 0};
With[{null = NullSpace[A]},
 LeastSquares[A, b] + Array[C, Length[null]].null
 ]

{1, C[1]}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.