Solve symbolic equation by comparing coefficients

24 ビュー (過去 30 日間)
Jörn Froböse
Jörn Froböse 2022 年 2 月 9 日
コメント済み: Jörn Froböse 2022 年 2 月 17 日
I have an equation like this: , which I need to rearrange to this form: .
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?
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
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])
eq2(a, b, c, d, e) = 
simplify(eq2)
ans(a, b, c, d, e) = 
D = solve(eq2 == 0, d)
D = 
E = solve(eq2 == 0, e)
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 😝 )
Jörn Froböse
Jörn Froböse 2022 年 2 月 10 日
Hey Highphi, thank you for your suggestion. This would'nt be really helpful in my case, since I need coefficients d and e without any dependence on x, y and z. I kind of solved it now by "brute-forcing" and using subs.

サインインしてコメントする。

採用された回答

Prachi Kulkarni
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
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);
Jörn Froböse
Jörn Froböse 2022 年 2 月 17 日
Thank you, this works for me!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by