Trying to solve 3 simultaneous equations, results seem erroneous

4 visualizaciones (últimos 30 días)
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])

Respuesta aceptada

Jan
Jan el 1 de Jun. de 2021
Editada: Jan el 1 de Jun. de 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 comentarios
Jan
Jan el 1 de Jun. de 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 el 2 de Jun. de 2021
Sorry @Jan, I think I've realised my error! You were correct, its the wrong methodology on my part!
Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by