Solve symbolic equation by comparing coefficients
조회 수: 6 (최근 30일)
이전 댓글 표시
I have an equation like this:
, which I need to rearrange to this form:
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/889545/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/889550/image.png)
Obviously, the above holds true
for
and
. However, I would like to do this automatically. How can d and e be found using Matlabs Symbolic Toolbox?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/889555/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/889560/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/889565/image.png)
The following approach won't help, since the system isn't well defined.
syms a b c d e f x y z
eq = a*x + y*(b + c*z)==0;
target = x + y*(d + e*z)==0;
solve([eq target],[d e])
Any help would be appreciated!
댓글 수: 2
Highphi
2022년 2월 9일
syms a b c d e f x y z
eq(a,b,c) = a*x + y*(b + c*z);
target(a,b,c,d,e) = x + y*(d + e*z);
eq2(a,b,c,d,e) = subs(eq, [b, c], [d*a, e*a])
simplify(eq2)
D = solve(eq2 == 0, d)
E = solve(eq2 == 0, e)
not sure if that helps much but maybe it'll help you get closer to where you want to be. (I'm not totally positive what you're trying to do with it 😝 )
채택된 답변
Prachi Kulkarni
2022년 2월 15일
편집: Prachi Kulkarni
2022년 2월 15일
Hi,
For a given example expression of the form a*x + y*(b + c*x), you can get the coefficients d and e of the reduced forms as follows.
syms x y z
eq = 2*x + y*(3 + 4*z); % input equation
[d,e] = reducedCoefficients(eq);
function [d,e] = reducedCoefficients(eq)
coef = coeffs(eq);
b = coef(1);
c = coef(2);
a = coef(3);
d = double(b/a);
e = double(c/a);
end
댓글 수: 4
Prachi Kulkarni
2022년 2월 17일
Hi,
For the general case, you can get the coefficients d and e of the reduced form as follows.
syms a b c x y z
eq = a*x + y*(b + c*z);
coef = coeffs(eq,[x,y,z]);
b = coef(1);
c = coef(2);
a = coef(3);
d = b/a;
e = c/a;
For your specific case, you can get the coefficients lambda and gamma of the reduced form as follows.
syms eta a Q d2ydt2 y t
eq = 4*(eta.^2)*d2ydt2 + 1.5*a*(Q.^2)*(1+cos(t))*y + y;
coef = coeffs(eq,[d2ydt2,y,cos(t)]);
lambda = coef(1)/coef(3);
gamma = coef(2)/coef(3);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!