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
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 个)
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]
Define m1 and m2 as the independent variables
syms m1 m2
assume(m2 > 0)
Use linsolve. It returns the expected solution.
linsolve(A,B)
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])
Verify by removing the assumption
assume(assumptions,'clear')
sol = solve(A*[m1;m2] == B,[m1 m2])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!