MATLAB Answers

Using equationTomatrix changes the order of units in the final matrix. How do you maintain the order?

4 views (last 30 days)
Keith Summers
Keith Summers on 19 Jan 2020
Commented: Keith Summers on 19 Jan 2020
So i'm trying to pass a sym function into a matrix using the equationToMatrix function but the function changes the order of the variables.
Result_2 =
a11
11*a1 + 10*a2 + 9*a3 + 8*a4 + 7*a5 + 6*a6 + 5*a7 + 4*a8 + 3*a9 + 2*a10 + a11
(11*a1)/1024 + (5*a2)/256 + (9*a3)/256 + a4/16 + (7*a5)/64 + (3*a6)/16 + (5*a7)/16 + a8/2 + (3*a9)/4 + a10 + a11
The equation to matrix function produces this
BB =
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
[ 11, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3]
[ 11/1024, 1, 1, 5/256, 9/256, 1/16, 7/64, 3/16, 5/16, 1/2, 3/4]
I undersand what is happening, matlab is ordering the variable a1 a10 a11 a12 a2 a3 etc. But there is not an oportunity that i know of to use the str2double function to stop this from happening. The order within the matrix is important as ultimately i will use linsolve to for a large system of equations. Also I've tried to use 'sort' but again because of the next step in the process this does not work. I'd really like to be able to somehow index from the syms funciton but it begins as a 1x1 entity.
Thanky for you help.

  0 Comments

Sign in to comment.

Sign in to answer this question.