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

조회 수: 2 (최근 30일)
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.

답변 (1개)

Walter Roberson
Walter Roberson 2020년 1월 19일
Pass in the vars option to the function to get the results to be in that order.

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by