Preventing matlab from reversing my signs in symbolic expressions
    4 views (last 30 days)
  
       Show older comments
    
    Leo Simon
      
 on 31 Mar 2015
  
    
    
    
    
    Commented: Walter Roberson
      
      
 on 17 Sep 2020
            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!
0 Comments
Accepted Answer
  Pranav Verma
    
 on 17 Sep 2020
        Hi Leo,
Please refer to the below discussion on the same lines:
Thanks
3 Comments
  Pranav Verma
    
 on 17 Sep 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
      
      
 on 17 Sep 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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

