Questions about arrangement of terms in Symbolic manipulation
8 views (last 30 days)
Show older comments
Here is my question about symbolic manipulation
1. Given that I declare the symbolic as
syms a b c d
2. I declare the function as,
f = d + a + b;
3. When I type 'f', it appears
f =
a + b + d
However, I want it to be
f =
d + a + b
What can I do in this case? As I know that in older version of MATLAB, eg MATLAB 7, if I declare the function in a prespecified order, then th function would be outputted in that prespecified order.
I now use newer version of MATLAB, MATLAB 2010. But I cannot get the output in the prespecified order. Therefore, can I do something to remedy the situation?
Thanks for your kind attention...
0 Comments
Answers (1)
Walter Roberson
on 13 Feb 2012
The older versions of MATLAB used the Maple symbolic engine, which would rearrange expressions in ways that were not obvious.
When you work with symbolic expressions, if the order of the terms matters to the calculation then you have done something wrong algebraically.
Extracting desired information from a symbolic expression can be a bit of a nuisance; you need lots of indets() and op() and coeff() or coeffs() calls. Unfortunately MuPAD's indets() is, in my experience, must more difficult to use than Maple's.
2 Comments
Walter Roberson
on 14 Feb 2012
Only if you make it a string, or if you use a different operator than _plus that keeps its order but prints out as if it is '+' (I think that trick is easier to pull in Maple.)
The symbolic engine _always_ rearranged symbols. MuPAD does it _less_ than Maple did.
If you need a particular order, consider constructing a MuPad procedure that prints the expression according to your rules -- or which constructs a string out of the expression. (Inside MuPAD it can be much easier to construct a "name" that happens to have spaces or other special characters in it. A "name" is enclosed in back-ticks. The mechanisms are like Maple's, but are not documented as obviously as for Maple.)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!