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

5 次查看(过去 30 天)
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:

采纳的回答

Walter Roberson
Walter Roberson 2018-2-5
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.

更多回答(1 个)

Query generator
Query generator 2025-2-27
编辑:Walter Roberson 2025-2-27
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.

产品

Community Treasure Hunt

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

Start Hunting!

Translated by