Difference between solve result

조회 수: 12 (최근 30일)
Boris
Boris 2023년 1월 30일
댓글: Walter Roberson 2023년 1월 31일
The follows equations get me usual result:
syms x y z
solve(x+y==4,y-z==0)
ans = struct with fields:
x: 4 - z y: z
But if I add true I have different one:
syms x y z
solve(x+y==4,y-z==0,true)
ans = struct with fields:
x: 4 y: 0 z: 0
That is mean true as input in function solve (I try to move true from end to begin and have the same result).

채택된 답변

Walter Roberson
Walter Roberson 2023년 1월 30일
When you solve() and you do not specify the names of variables to solve for, the solve() uses symvar() and takes as many variables as there are equations. So when you passed in 3 equations, it took the first three variables from symvar(); when you pass in two equations, it took the first two variables from symvar()
Treated as a system of 3 equations, the equations are underdetermined in z. The result from solve() is similar to the case where some of the equations are inequalities. That is, the internal computation knows to return parameterized solutions and range expressions, but then the interface code that converts the internal representation to something to show to the user chooses a specific "representative" value and substitutes that.
syms x y z
internal_results = feval(symengine, 'solve', [x+y==4, y-z==0, symtrue], [x, y, z])
internal_results = 
The general rule of thumb when MATLAB is chosing a representative value, is that if 0 is valid within the constraints of the value, then the representative value will be 0. Applying that to above, the represenative value 0 is chosen for and that leads to the [4 0 0] output that you observe.
  댓글 수: 2
Boris
Boris 2023년 1월 31일
Thank you for the help.
Walter Roberson
Walter Roberson 2023년 1월 31일
Minor correction: solve() does sort(symvar()) to determine the variables to solve for.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by