Symbolic équation factorisation : how to identify automatically the factor in front one variable and put it into a variable

8 次查看(过去 30 天)
Hello,
I have a system of very long symbolic equations with many different symbolic variables which could be factorized that way:
B1=A11*V1+A12*V2+.....+A1n*Vn
:
Bm=Am1*V1+Am2*V2+.....+Amn*Vn
The coefficients Aij are a sum and multiplication of different symbolic variables and I would like to extra it to put it in a symbolic array. Is there a matlab function that I don,t know of capable of doing this?
Thank you for your time, Rémy
PS: Here is a simple example: The two equations I could have :
a=e*c*V1-c*V2+d*V1+f
b=d*e*V2+e*V1+f*d*V1+e*f*V2+e
I would like to be able to identify automatically the factors in front of Vi and put them into an array such as:
B(1)=a-f
B(2)=b-e
A(1,1)=e*c+d
A(1,2)=-c
A(2,1)=e+f*d
A(2,2)=d*e+e*f
  2 个评论
Walter Roberson
Walter Roberson 2018-6-22
Your example is confusing, as you define a in terms of c and then define c in term of a, which would requires that a be expanded, and so end up defining c in terms of c . When you do that kind of thing, you are almost certain to end up with nonlinear equations, whereas your B1..Bm form is strictly linear forms.
Rémy Bretin
Rémy Bretin 2018-6-22
编辑:Rémy Bretin 2018-6-22
Oh yeah excuse me, I tried to make up a simple example, and I haven't realized that mistake, I will correct it.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2018-6-22
syms a b c d V1 V2 x
E1 = b*c*V1-c*V2+d*V1+b;
E2 = d*x*V2+a*V1+b*d*V1+a*b*V2+a;
E3 = d*b*V2 + c; %suppose V1 coefficient is 0?
eqns = [E1;E2;E3];
neqns = length(eqns);
vars = [V1;V2];
nvars = length(vars);
A = zeros(neqns, nvars + 1, 'sym');
extvars = [sym(1); vars];
for eqidx = 1 : neqns
[P,Q] = coeffs(eqns(eqidx), vars);
[tf, exvidx] = ismember(Q, extvars);
A(eqidx, exvidx(tf)) = P(tf);
end
B = A(:,1);
A = A(:,2:end);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by