Trying to solve 3 simultaneous equations, results seem erroneous

1 view (last 30 days)
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])

Accepted Answer

Jan
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?
  3 Comments
Jan
Jan on 1 Jun 2021
The result of A\b is a vector. I do not undestand why adding its elements and multiplying the result by 0:255 is meaningful. If xSol+ySol+zSol is negative, multiplying it with non-negative numbers must produce a non-negative result. In you case it is: -0.1884 * (0:255). How could this be positive?
Teshan Rezel
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!

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!