0
$\begingroup$

I have a linear system of 22 equations and variables. When I create the matrix form it sorts the coefficients on the first row (X1, X10, X11, ...) This ordering repeats for all columns and all the results have the same order.

How do I sort the matrix to be in each row this way: (X1, X2, X3, ..., X22)?

X1,X2 and those are suppsoed to be the constant accompanying my coefficients which are x1,x2 ,x3 ...x22.

I have tried using sort, but I dont find a simple way at least to sort the results or sort the coefficients of the matrix. I am using the following function to create the matrix:

M = Normal[CoefficientArrays[system]][[2]];
MatrixForm[M]

where system contains all my 22 equations.

The methods I used to solve the system give me the same result, which is correct. Both Solve[system] and LinearSolve[M , B] give me the correct results but sorted like X1, X12, and so on.

$\endgroup$
  • $\begingroup$ Maybe rename your coefficients X01, X02, ..., X22 and your variables x01, x02, ..., x22? $\endgroup$ – m_goldberg Apr 4 '18 at 7:52
  • 1
    $\begingroup$ This problem should resolve if you enter the list of variable names in desired order as the second argument to CoefficientArrays, precisely as it is written in the documentation. $\endgroup$ – Henrik Schumacher Apr 4 '18 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.