# Solving a set of equations

I'm trying to use Mathematica to solve a set of equations. The data are experimental data and won't produce exact perfect answers for every equation. An approximate answer for each variable is acceptable.

I'm looking for insight into other techniques that might help me solve the set of equations other then Solve. My code is below. The correct answer will solve for -18 < a < -19. Any advice is appreciated.

Solve[{
4 a == -74.6,
3 a + b + f == -239.2,
a 5 + b 1 + c + f == -277.6,
a 6 + b 2 + d == -248.4,
a 7 + b 2 + c + f == -215.6,
a 10 + g + b 3 == -46.9,
a 12 + b 3 + c 2 == -313.6,
h 6 + j == 49.1,
a 12 + b 6 == -156.4},
{a, b, c, d, f, g, h, j}]

• Your last equation contains "CC". Did you mean "c" ? Also, have you seen LeastSquares ? – LouisB Jun 13 '17 at 3:56
• This set of equations is just the beginning of a larger set of data. I'm really seeking advice on Mathematica techniques on solving similar problems. Solve doesn't work. I will look in to least squares and fix the CC code. Thanks for your input. – Otto Omen Jun 13 '17 at 4:07
• After looking through the answers the Solve command ended up producing the correct answer. Gold posted a complete analysis of the question below. – Otto Omen Jun 13 '17 at 14:36

Your system has three equations that are inconsistent with each other

a 5 + b + c + f == -277.6
a 7 + b 2 + c + f == -215.6
a 12 + b 3 + c 2 == -313.6


and one equation that is completely independent of all the others and can't be solved.

6 h + j == 49.1


So there are three possible consistent systems for which you can get solutions. Only the value of c differs among these systems.

Clear[a, b, c, d, f, g];
Solve[
{4 a == -74.6,
3 a + b + f == -239.2,
a 6 + b 2 + d == -248.4,
a 10 + g + b 3 == -46.9,
a 12 + b 3 + c 2 == -313.6,
a 12 + b 6 == -156.4},
{a, b, c, d, f, g}]


{{a -> -18.65, b -> 11.2333, c -> -61.75, d -> -158.967, f -> -194.483, g -> 105.9}}

Clear[a, b, c, d, f, g];
Solve[
{4 a == -74.6,
3 a + b + f == -239.2,
a 6 + b 2 + d == -248.4,
a 10 + g + b 3 == -46.9,
a 5 + b + c + f == -277.6,
a 12 + b 6 == -156.4},
{a, b, c, d, f, g}]


{{a -> -18.65, b -> 11.2333, c -> -1.1, d -> -158.967, f -> -194.483, g -> 105.9}}

Clear[a, b, c, d, f, g];
Solve[
{4 a == -74.6,
3 a + b + f == -239.2,
a 6 + b 2 + d == -248.4,
a 10 + g + b 3 == -46.9,
a 7 + b 2 + c + f == -215.6,
a 12 + b 6 == -156.4},
{a, b, c, d, f, g}]


{{a -> -18.65, b -> 11.2333, c -> 86.9667, d -> -158.967, f -> -194.483, g -> 105.9}}

• Thanks Goldberg. This is answer I was looking for. I realized there was in independant equation. I thought mathematica might solve for one variable in terms of the other instead of producing a numerical result. I also realized how important the clear command was in this problem. It might have been the main reason I was getting unusual results until in the beginning. – Otto Omen Jun 13 '17 at 14:32

Perhaps you want this (as your matrix is singular):

  b = {-74.6, -239.2, -277.6, -248.4, -215.6, -46.9, -313.6,
49.1, -156.4};
m = {{4, 0, 0, 0, 0, 0, 0, 0}, {3, 1, 0, 0, 1, 0, 0, 0}, {5, 1, 1, 0,
1, 0, 0, 0}, {6, 2, 0, 1, 0, 0, 0, 0}, {7, 2, 1, 0, 1, 0, 0,
0}, {10, 3, 0, 0, 1, 0, 0, 0}, {12, 3, 2, 0, 0, 0, 0, 0}, {0, 0,
0, 0, 0, 0, 6, 1}, {12, 6, 0, 0, 0, 0, 0, 0}};
x = PseudoInverse[m].b;
ListPlot[{b, m.x}, PlotStyle -> {Blue, Red}, Joined -> {False, True}]
Thread[{"a", "b", "c", "d", "f", "g", "h", "j"} -> x]
(b - m.x).(b - m.x)