# Trying to solve 3 simultaneous equations, results seem erroneous

1 view (last 30 days)
Teshan Rezel on 1 Jun 2021
Commented: Teshan Rezel on 2 Jun 2021
Hi folks,
I am trying to solve the following set of equations. However, when plotting the results from the coefficients, I get all negative values when in reality, I'm expecting positive ones. Even the original equations have positive outcomes. Can you please advise on where I've gone wrong?
syms x y z
eqn1 = 109*x + 54*y + 124*z == 7.51;
eqn2 = 57*x + 30*y +63*z == 3.17;
eqn3 = 30*x + 17*y + 31*z == 1.24;
sol = solve([eqn1, eqn2, eqn3], [x, y, z]);
xSol = sol.x
ySol = sol.y
zSol = sol.z
a = 0:255;
ref = a*(xSol + ySol + zSol);
plot(ref)
xlim([0 255])

Jan on 1 Jun 2021
Edited: Jan on 1 Jun 2021
syms x y z
eqn1 = 109*x + 54*y + 124*z == 7.51;
eqn2 = 57*x + 30*y +63*z == 3.17;
eqn3 = 30*x + 17*y + 31*z == 1.24;
sol = solve([eqn1, eqn2, eqn3], [x, y, z]);
sol.x, sol.y, sol.z
ans =
ans =
ans =
This can be solved numerically also:
A = [109, 54, 124;
57, 30, 63;
30, 17, 31];
b = [7.51; 3.17; 1.24];
x = A \ b
% [0.4529; -0.5380; -0.1033]
Of course, this is the same result.
So I assume, the only problem is:
ref = (0:255) * (xSol + ySol + zSol);
What is the purpose of adding the elements of the solution and multiplying it with a vector?
Teshan Rezel on 2 Jun 2021
Sorry @Jan, I think I've realised my error! You were correct, its the wrong methodology on my part!
Thanks!

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by