Assumptions are not being considered in symbolic math.

9 ビュー (過去 30 日間)
Nick Knowles
Nick Knowles 2024 年 3 月 4 日
回答済み: Paul 2024 年 3 月 5 日
I am trying to solve a system of equations using symbolic math. It's a mass balance around a system. It gives zero values for some outputs, but that is not what I am looking for. I have added "assume(m3>0)" for example, however m3 still comes out as zero.
  1 件のコメント
John D'Errico
John D'Errico 2024 年 3 月 4 日
The assumptions were "considered". But then MATLAB realized the assumption was inconsistent with the problem, and ignored it, since it had to ignore something.
You have a full rank, linear system of equations. There will be EXACTLY one solution, ALWAYS. If the solution has one of the variables equal to zero, so be it. Assume as much as you wish. Stamp your feet too, bang your fist on the table, if you think it will help. It won't. ;-)

サインインしてコメントする。

回答 (2 件)

Torsten
Torsten 2024 年 3 月 4 日
編集済み: Torsten 2024 年 3 月 4 日
What is rank(A) ? If it's 8, your system of equations has a unique solution, and you can't assume anything about it.
  2 件のコメント
Nick Knowles
Nick Knowles 2024 年 3 月 4 日
rank(A) is 8
Torsten
Torsten 2024 年 3 月 4 日
Then the m1,...,m8 you get are the only possible values that satisfy A*[m1;m2;m3;m4;m5;m6;m7;m8] = B.

サインインしてコメントする。


Paul
Paul 2024 年 3 月 5 日
Hi Nick
The issue is that the code is using linsolve, which doesn't know anything about the assumptions on the m_i.
Generate an example of A and B
A = sym([1 2;3 4]);
B = A*[2;0]
B = 
Define m1 and m2 as the independent variables
syms m1 m2
assume(m2 > 0)
Use linsolve. It returns the expected solution.
linsolve(A,B)
ans = 
The original problem used equationsToMatrix to form A and B. The assumptions on m_i have nothing to do with A and B.
solve respects the assumption, which is why it doesn't return a solution (solve does have a name/value input that can be used to ignore assumptions)
sol = solve(A*[m1;m2] == B,[m1 m2])
sol = struct with fields:
m1: [0×1 sym] m2: [0×1 sym]
Verify by removing the assumption
assume(assumptions,'clear')
sol = solve(A*[m1;m2] == B,[m1 m2])
sol = struct with fields:
m1: 2 m2: 0

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by