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)
% unsuccessful attempt using [psi; C; D]
sol2 = solve(B, [psi; C], "Real", true, "ReturnConditions", true)
0 个评论
采纳的回答
Star Strider
2021-12-15
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Algebra 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!