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.
Asked
Active
Viewed 713 times
1
-
have you tried to look at Symbolic Matlab Toolbox? http://www.mathworks.com/help/toolbox/symbolic/f1-82523.html#f1-56798 – Lordalcol Feb 04 '11 at 16:26
-
Are you dealing with [symbolic equations](http://www.mathworks.com/products/symbolic/)? – gnovice Feb 04 '11 at 16:26
2 Answers
1
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.
0
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.

JC2
- 141
- 1
- 4
- 11