sym/solve: input order relevant for solution success?
1 view (last 30 days)
Show older comments
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)
% unsuccessful attempt using [psi; C; D]
sol2 = solve(B, [psi; C], "Real", true, "ReturnConditions", true)
0 Comments
Accepted Answer
Star Strider
on 15 Dec 2021
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)
% successful attempt using [C; psi]
sol1 = solve(B, [C; psi], "Real", true, "ReturnConditions", true)
% unsuccessful attempt using [psi; C; D]
sol2 = solve(B, [psi; C], "Real", true, "ReturnConditions", true)
.
0 Comments
More Answers (0)
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!