Trying to solve 3 simultaneous equations, results seem erroneous

4 次查看(过去 30 天)
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
Jan 2021-6-1
编辑:Jan 2021-6-1
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 个评论
Jan
Jan 2021-6-1
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 2021-6-2
Sorry @Jan, I think I've realised my error! You were correct, its the wrong methodology on my part!
Thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by