sym/solve: input order relevant for solution success?

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by