在MATLAB中对术语进行分组 [英] Grouping like terms in MATLAB

查看:76
本文介绍了在MATLAB中对术语进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个程序来解决MATLAB中的方程组.我想知道是否有一种方法可以让MATLAB将类似的术语归为一组并将其系数放入矩阵中?我意识到我可以手动输入系数,但是我希望希望重新利用这个小程序来进行节点分析.

I'm trying to code a program that solves systems of equations in MATLAB. I was wondering if there is a way to get MATLAB to group like terms and put their coefficients into a matrix? I realize that I can just enter the coefficients in by hand but I want to hopefully repurpose this small program to perform nodal analysis.

推荐答案

您可以随时使用我的符号工具为您完成大部分工作.由于这套工具将使您可以直接访问已解析的结果,因此将使您的工作更加轻松,并对表达式进行很多符号操作.例如...

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

在文件交换中找到符号.

这篇关于在MATLAB中对术语进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆