Preventing matlab from reversing my signs in symbolic expressions

12 visualizaciones (últimos 30 días)
The symbolic toolbox reverses the signs of the expressions I type. For example
syms a b
f = (1-x)*a + b
returns
b - a*(x-1)
Is there some option I can set somewhere to prevent this sign reversal, and have the above return
b + a*(1-x)
I know it's a small thing, but when x is always less than 1, it's annoying.
Thanks!

Respuesta aceptada

Pranav Verma
Pranav Verma el 17 de Sept. de 2020
  3 comentarios
Pranav Verma
Pranav Verma el 17 de Sept. de 2020
I agree with you Leo that thread does not provide the exact resolution to the issue, but as Walter has indicated in his answer, the symbolic toolbox indeed has some preference rules for commutative expressions and it converts the expression according to those rules albeit that doesn't change the final result that is expected.
Walter Roberson
Walter Roberson el 17 de Sept. de 2020
The behavior I described there is what the symbolic engine does, and there is no provision for changing it.
You could construct expressions with more specific forms by using feval(symengine, 'hold', SUBEXPRESSION) on parts of the expression and joining the resulting subexpressions together with appropriate MuPAD operators. But that will not do you much good, as MATLAB will reset the symbolic engine if it notices hold() operators in the expressions (that is, it does not expect them to show up and it resets itself when unknown things show up.) If you char() a symbolic expression that includes a hold() then you will get back a character vector that includes internal symbolic references that the user cannot make much sense of. MuPAD does take hold() into account in computation.... the problem is that it isn't Computation you want, it is Presentation.
I am not saying that it cannot be changed... but changing it would require digging hard into the MuPAD code that drives the symbolic engine, and providing an alterated version of that code to the symbolic engine. You would have to do all the development work in R2019b or earlier, as the MuPAD development tools got striped out in R2020a.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by