フィルターのクリア

sym/solve: input order relevant for solution success?

1 回表示 (過去 30 日間)
Fabia Bayer
Fabia Bayer 2021 年 12 月 15 日
回答済み: Star Strider 2021 年 12 月 15 日
Hello,
when I use the symbolic toolbox to solve some equations, I stumbled upon a case where the specified order of input variables influences whether the toolbox can successfully solve the equation or not. From the documentation of sym/solve and related answers, I could not find any indication that this should take place. MWE see below.
My question is - is this a bug that should be reported? If not, how can I systematically find successful orders of variables except by brute force (for my application, there will generally be more than 2 input variables)?
I initially had the problem using Matlab 2021a on Windows and it also seems to appear in this 2021b web version.
Thank you very much.
MWE (Harmonic Balance equations for Duffing oscillator - edited to make it more minimal while retaining the effect):
syms a b gamma omega real positive
syms C psi real
assumeAlso(C > 0);
assumeAlso(psi >= 0);
assumeAlso(psi < 2*pi);
B = [-0.7500*b*cos(psi)*C^3 + cos(psi)*C*omega^2 - a*sin(psi)*C*omega - cos(psi)*C + gamma;...
0.2500*C*(4*sin(psi) - 4*omega^2*sin(psi) - 4*a*omega*cos(psi) + 3*C^2*b*sin(psi))];
% successful attempt using [C; psi]
sol1 = solve(B, [C; psi], "Real", true, "ReturnConditions", true)
sol1 = struct with fields:
C: (a^3*omega^3*x^4 - a^3*omega^3 - 2*a^2*omega^4*x^3 - 2*a^2*omega^4*x + 2*a^2*omega^2*x^3 + 2*a^2*omega^2*x + 6*b*gamma^2*x)/(3*a*b*gamma*omega) psi: 2*atan(x) + 2*pi*k parameters: [k x] conditions: atan(x) + pi*k < pi & a^3*omega^3 + 2*a^2*omega^4*x^3 + 2*a^2*omega^4*x < a^3*omega^3*x^4 + 2*a^2*omega^2*x^3 + 2*a^2*omega^2*x + 6*b*gamma^2*x & in(k, 'integer') & in(x, 'real') & a^3*omega^3*x^6 + a^3*omega^3*x^4 + 2*a^2*omega^2*x^5 …
% unsuccessful attempt using [psi; C; D]
sol2 = solve(B, [psi; C], "Real", true, "ReturnConditions", true)
Warning: Unable to find explicit solution. For options, see help.
sol2 = struct with fields:
psi: [0×1 sym] C: [0×1 sym] parameters: [1×0 sym] conditions: [0×1 sym]

採用された回答

Star Strider
Star Strider 2021 年 12 月 15 日
Use the simplify function first, and both sork —
syms a b gamma omega real positive
syms C psi real
assumeAlso(C > 0);
assumeAlso(psi >= 0);
assumeAlso(psi < 2*pi);
B = [-0.7500*b*cos(psi)*C^3 + cos(psi)*C*omega^2 - a*sin(psi)*C*omega - cos(psi)*C + gamma;...
0.2500*C*(4*sin(psi) - 4*omega^2*sin(psi) - 4*a*omega*cos(psi) + 3*C^2*b*sin(psi))];
B = simplify(B, 500)
B = 
% successful attempt using [C; psi]
sol1 = solve(B, [C; psi], "Real", true, "ReturnConditions", true)
sol1 = struct with fields:
C: z psi: z1 parameters: [z z1] conditions: z*cos(z1)*omega^2 - a*z*sin(z1)*omega + gamma - z*cos(z1) - (3*b*z^3*cos(z1))/4 == 0 & z1 < 2*pi & ((z*tan(z1/2)*(- 4*omega^2 + 3*b*z^2 + 4))/2 - 2*a*omega*z)/(tan(z1/2)^2 + 1) + a*omega*z == 0 & 0 < z & 0 <= z1
% unsuccessful attempt using [psi; C; D]
sol2 = solve(B, [psi; C], "Real", true, "ReturnConditions", true)
sol2 = struct with fields:
psi: z C: z1 parameters: [z z1] conditions: z1*cos(z)*omega^2 - a*z1*sin(z)*omega + gamma - z1*cos(z) - (3*b*z1^3*cos(z))/4 == 0 & z < 2*pi & ((z1*tan(z/2)*(- 4*omega^2 + 3*b*z1^2 + 4))/2 - 2*a*omega*z1)/(tan(z/2)^2 + 1) + a*omega*z1 == 0 & 0 < z1 & 0 <= z
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by