Assumptions are not being considered in symbolic math.

6 次查看(过去 30 天)
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.

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

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by