Linsolve doesn't find solution to overdetermined system
3 ビュー (過去 30 日間)
古いコメントを表示
Matlab solves the following system correctly:
syms x y z A B C D E
eqn1 = 3*x + 1*y - 1*z == A;
eqn2 = 2*x - 2*y + 4*z == B;
eqn3 = -1*x + 0.5*y - 1*z == C;
%eqn4 = 2*x + 1*y + 0*z == D;
[AA,BB] = equationsToMatrix([eqn1, eqn2, eqn3], [x, y, z]);
X = linsolve(AA,BB);
solution:
- B/2 - 2*C
2*A + 4*B + 14*C
A + (5*B)/2 + 8*C
However if you add that 4th equation it will return:
Warning: Solution does not exist because the system is inconsistent.
That's not actually true? The solution should stay the same with the additional constraint that : D = 2 A + 3 B + 10 C
You can get it to work in Matlab if you ask it to solve for D as well:
[AA,BB] = equationsToMatrix([eqn1, eqn2, eqn3], [x, y, z, D]);
X = linsolve(AA,BB);
solution:
- B/2 - 2*C
2*A + 4*B + 14*C
A + (5*B)/2 + 8*C
2*A + 3*B + 10*C
But It does not work if you ask it to solve for all the variables:
[AA,BB] = equationsToMatrix([eqn1, eqn2, eqn3], [x, y, z, A, B, C, D]);
X = linsolve(AA,BB);
It will say that the solution is not unique because the matrix is rank deficient. That's not tue? The solution is still fully unique with that same one extra constraint D = 2 A + 3 B + 10 C. Solving it in terms of D also fully solves it in terms of A, B, C.
What is going on here? Is it that the solver always needs to solve for the same amount of variables as the rank of the matrix?
0 件のコメント
採用された回答
Matt J
2019 年 3 月 12 日
編集済み: Matt J
2019 年 3 月 12 日
Linsolve will try to solve only for those variables that you specify as unknowns. The rest are treated as constants. So, the things you call "constraints" like D = 2 A + 3 B + 10 C are not valid when the only specified unknowns are x,y,z because constraints cannot be imposed on constants.
Your first failed case happens because a solution to all 4 equations cannot be found when x,y,z are the only free variables. In the second case, the solution is indeed not unique, because you have 4 equations and 7 unknowns.
However, you can get the effect you want by using a different solver,
s=solve([eqn1,eqn2,eqn3,eqn4])
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Stability Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!