# LinearSolve with 4 variables and 3 equations [closed]

Is it possible to find a solution or at least run LinearSolve when there are 4 variables and 3 equations.

For example:

a + b -3c + 4d = 4; 2a + 5b -6c +2d = 15; 3a -4b + 5c -3d = 10.

• With 3 equations and 4 variables you can only hope 3 variables as functions of the 4'th variable. Solve will do the job Jan 22 at 9:58
• This query now not related to Mathematica but linear algebra. When it is said '3 variables as functions of the 4th variable', does it mean 3 can be any of a,b,c,d and 'function of the 4th variable' the remaining one. Jan 22 at 10:38
• Usually, any three of {a,b,c,d} can be functions of the 4th variable. Jan 22 at 17:28

Here is an example:

eq = {a + b - 3 c + 4 d == 4, 2 a + 5 b - 6 c + 2 d == 15,
3 a - 4 b + 5 c - 3 d == 10};
Solve[eq, {a, b, c}]
Solve[eq, {a, b, d}]
Solve[eq, {a, c, d}]
Solve[eq, {b, c, d}]


• Yes, it clarified. Jan 22 at 10:55
• I find it strange if the solution set (using LinearSolve) can be a set of four numbers. For instance {1,2,3,0}. I am not reproducing the actual problem since it is part of an exercise that Wolfram prohibits sharing. I can share on message though. Jan 22 at 11:47

Your system of equations can be written in matrix form:

M = {{1, 1, -3, 4},
{2, 5, -6, 2},
{3, -4, 5, -3}};
q = {4, 15, 10};

Thread[M . {a, b, c, d} == q]
(*    {a + b - 3 c + 4 d == 4,
2 a + 5 b - 6 c + 2 d == 15,
3 a - 4 b + 5 c - 3 d == 10}    *)


As @DanielHuber points out, there are infinitely many solutions $$x=\{a,b,c,d\}$$. The one with smallest norm can be found through the Moore–Penrose pseudoinverse of M:

x0 = PseudoInverse[M] . q
(*    {2781/610, 1817/2745, -3883/5490, -2294/2745}    *)


All other solutions differ from x0 by any vector from the nullspace of M: (here the nullspace only contains one vector)

n = NullSpace[M]
(*    {{3, 28, 29, 14}}    *)

x[t_] = x0 + {t} . n
(*    {2781/610 + 3 t,
1817/2745 + 28 t,
-3883/5490 + 29 t,
-2294/2745 + 14 t}    *)


Check:

M . x[t] == q // Expand
(*    True    *)

• Alternatively x0 = LeastSquares[M, q] Jan 22 at 19:10
• So LinearSolve[A,b] in case of 3 equations and 4 variables with give output of the one with the smallest norm? Jan 23 at 7:46
• Yes, just like the Moore–Penrose pseudoinverse. Jan 23 at 17:02