Symbolic équation factorisation : how to identify automatically the factor in front one variable and put it into a variable
조회 수: 5 (최근 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
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.
채택된 답변
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);
댓글 수: 2
Walter Roberson
2018년 6월 22일
Much more simple:
>> [A,B] = equationsToMatrix(eqns,vars)
A =
[ d + b*c, -c]
[ a + b*d, a*b + d*x]
[ 0, b*d]
B =
-b
-a
-c
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!