1
$\begingroup$

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.

$\endgroup$
3
  • 2
    $\begingroup$ With 3 equations and 4 variables you can only hope 3 variables as functions of the 4'th variable. Solve will do the job $\endgroup$ Jan 22 at 9:58
  • $\begingroup$ 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. $\endgroup$ Jan 22 at 10:38
  • $\begingroup$ Usually, any three of {a,b,c,d} can be functions of the 4th variable. $\endgroup$
    – bbgodfrey
    Jan 22 at 17:28

2 Answers 2

4
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ Yes, it clarified. $\endgroup$ Jan 22 at 10:55
  • $\begingroup$ 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. $\endgroup$ Jan 22 at 11:47
6
$\begingroup$

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    *)
$\endgroup$
3
  • 2
    $\begingroup$ Alternatively x0 = LeastSquares[M, q] $\endgroup$
    – Michael E2
    Jan 22 at 19:10
  • $\begingroup$ So LinearSolve[A,b] in case of 3 equations and 4 variables with give output of the one with the smallest norm? $\endgroup$ Jan 23 at 7:46
  • $\begingroup$ Yes, just like the Moore–Penrose pseudoinverse. $\endgroup$
    – Roman
    Jan 23 at 17:02

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