Grouping like terms in MATLAB

坚强是说给别人听的谎言 提交于 2019-12-07 08:00:30

You could always use my sympoly tools to do much of the work for you. Since this set of tools will give you direct access to the parsed result, this will make your life easier, as well as do much symbolic manipulation of an expression. For example...

>>sympoly x y z
>> P = 3*x + 2*x*y - 2.75*z^2
P =
    -2.75*z^2 + 3*x + 2*x*y

>> struct(P)
ans = 
            Var: {'x'  'y'  'z'}
       Exponent: [3x3 double]
    Coefficient: [3x1 double]

>> P.Exponent
ans =
     0     0     2
     1     0     0
     1     1     0
>> P.Coefficient
ans =
                     -2.75
                         3
                         2

Find sympoly on the file exchange.

It would be easy enough to write a parser in order to do this functionality yourself. Parse out the number and then the variable with its power. Good luck.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!