matlab solve gives wrong output
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I try to solve following equations with this code:
First i declare some parameters:
d35y=5;
d35z=5;
d37y=10;
d37z=10;
d57y=5;
d57z=5;
F3y = 10;
F3z = -20;
Then i declare the variables and solve it:
syms F5y F5z F7y F7z;
a = - F5y + F7y - F3y;
b = F5z + F7z + F3z;
c = -(d57z*F7y) + (d57y*F7z) - (d35z*F3y) - (d35y*F3z);
d = (d35y*F5z) - (d35z*F5y) + (d37y*F7z) + (d37z*F7y);
[F5y, F5z, F7y, F7z] = solve(a,b,c,d);
F5y = double(F5y)
F5z = double(F5z)
F7y = double(F7y)
F7z = double(F7z)
As output it SHOULD give me (when i calculate it by hand it is correct):
F5y = -20
F5z = 40
F5y = -10
F5z = -20
However MATLAB gives me this as output:
F5y = -20
F5z = -10
F7y = 40
F7z = -20
--> which is *not* correct.
Why does MATLAB gives me an incorrect answer?
Thanks in advance !
0 Commenti
Risposte (1)
Walter Roberson
il 5 Giu 2015
Try specifying the order of the variables explicitly,
[F5y, F5z, F7y, F7z] = solve(a,b,c,d, F5y, F5z, F7y, F7z);
Alternately, return an output structure
sol = solve(a,b,c,d);
[sol.F5y, sol.F5z, sol.F7y, solve.F7z]
2 Commenti
Walter Roberson
il 5 Giu 2015
Is it possible that one of the two has Maple installed as the symbolic toolbox?
The order you used for the variables is what is documented, which is to say the order used by symvar() which should have sorted the way you wanted. But I never count on that ordering, which is a bit odd.
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!