3
$\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
  • 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$ Commented Jan 20, 2024 at 5:18

1 Answer 1

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$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.