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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by