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$?


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?

  • 3
    $\begingroup$ This will give a form of parametrized solution set: xx = Array[x,2];Solve[A.xx==b,xx] $\endgroup$ Commented Apr 11, 2018 at 13:39
  • $\begingroup$ Still need a new way to calculate this in Mathematica. $\endgroup$
    – Y. zeng
    Commented Jan 20 at 5:18

1 Answer 1


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]}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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