Trying to solve 3 simultaneous equations, results seem erroneous

4 ビュー (過去 30 日間)
Teshan Rezel
Teshan Rezel 2021 年 6 月 1 日
コメント済み: Teshan Rezel 2021 年 6 月 2 日
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 Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by