Message Boards Message Boards

0
|
6126 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Sort a multilinear equation on its coefficients?

Posted 7 years ago

What's the easy way to display a multilinear equation as sorted on its coefficients? For instance, display

7 + 3x[1] - 2x[2] + x[3] 

as

7 - 2x[2] + x[3] + 3x[1]

I'm now converting the equation into a list of {coefficient, variable} pairs, sorting on the first component, and then constructing the desired display. It's easy enough but I'm hoping there's an easier way.

Thanks.

POSTED BY: Bruce Colletti
2 Replies
Posted 7 years ago

This is great, Gianluca. Thanks.

POSTED BY: Bruce Colletti

This almost does it:

SortBy[7 + 3 x[1] - 2 x[2] + x[3] /. 
  Plus -> Inactive[Plus], # /. x[_] -> 1 &]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract