Is there a way to force the format of symbolic equations to list the symbols in the order that they were entered?

2 vues (au cours des 30 derniers jours)
I am trying to enter a symbolic equation to be displayed in a LiveScript but the output is always re-arranged from the order I entered the equation. Is there a way to force the output to display in the symbol order/format that it was entered? I realize the mathematically the formulas are equal but it can lead to confusion in many cases. For example, in the following screen shot, look at the order of x_L and x_E in the last equation. At first glance it looks as if the sign has changed on each squared term even though it is mathematically correct due to terms being squared:

Réponse acceptée

Walter Roberson
Walter Roberson le 5 Fév 2018
No, there is no way to do that in livescript. Doing this in the Symbolic Toolbox at all would require using feval(symengine) or evalin(symengine) to create a formula with a series of embedded hold() calls .
Even then, the symbolic _plus operation and _subtract operation and _multiply operation all know about commutivity, so you might have to create a new MuPAD DOM with appropriate slots for operations that somehow held the order until you asked it specifically to evaluate (at which point it would be re-order time.)
Livescript does not support formatting of internal hold() operations into nice display text.

Plus de réponses (1)

Query generator
Query generator le 27 Fév 2025
Modifié(e) : Walter Roberson le 27 Fév 2025
I know this is a very old question but, in case anyone else was wondering, have a look at the following - this should display the equation as written:
clear;
u = symunit;
syms a b c d e f
equation_1_str = 'f == e*b*c + a + a^2/(d*c^2)';
displayFormula(equation_1_str)
equation_1_syms = str2sym(equation_1_str);
disp(equation_1_syms)
% Note, the symbolic conversion rearranges the equation.
  2 commentaires
BrentB
BrentB le 27 Fév 2025
Thanks Walter. That is a good work around for what I was trying to accomplish.
Walter Roberson
Walter Roberson le 27 Fév 2025
It wasn't me who answered -- I just reformated some of their text as a code section.

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by