A complicated answer from 'solve' function
古いコメントを表示
Here is a simple M code:
syms Omega t delta C M
tn=solve(Omega*sin(Omega*t-delta) + C*cos(Omega*t - delta)*1/(2*M), t)
Then, the answer from MATLAB Symbolic Toolbox is
(delta + log((- C^2 - 4*M^2*Omega^2)^(1/2)/(C + M*Omega*2i))*1i)/Omega
(delta + log(-(- C^2 - 4*M^2*Omega^2)^(1/2)/(C + M*Omega*2i))*1i)/Omega
Meanwhile, when I solve the equation in the M code by hand yields this:
1/Omega * atan(-C/2/M/Omega) + delta/Omega
I can't draw a straight line between my handwritten answer and the answer given by MATLAB. Would you help me to understand the answer from MATLAB?
In Kwon Park
回答 (1 件)
John D'Errico
2017 年 12 月 26 日
編集済み: John D'Errico
2017 年 12 月 26 日
Very often, the answer is that the symbolic toolbox does not see what seems obvious to you.
Yes, it seems clear that by dividing by cos(Omega*t-delta), that you can collect those two terms into a tangent.
tan(Omega*t-delta) = -C/(2*M)/Omega
It requires that cos(Omega*t-delta) not be zero to be valid, or else you have a problem. Yes, we see that when the cos term in question is zero, then the tangent function goes through a singularity. Of course, given that, it is now possible to see how you solved the problem, and the symbolic toolbox has no issue, if I take that step for it:
tn=solve(tan(Omega*t-delta) + C/(2*M)/Omega,t)
tn =
(delta - atan(C/(2*M*Omega)))/Omega
But that is seen from a bird's eye view. Instead, what did the symbolic toolbox do? It appears it chose to avoid creating a singularity, but to use a different approach. One alternative approach might be to use the relation
cos(u) = +/- sqrt(1-sin(u)^2)
So, if u=Omega*t-delta and v=sin(u), then your problem reduces to something like
Omega*v = +/- C*sqrt(1-v^2)/(2*M)
Solve for v by squaring, and we would get a solution, although we would need to resolve any spurious roots created by that squaring. To me, the solution that you post seems vaguely quadratic, so suggestive of the second approach I took. Interestingly, when I try the same solve as you wrote, MATLAB finds no solution at all. So I'm not totally confident that you did truly get that solution. (In R2017b)
syms Omega t delta C M
tn=solve(Omega*sin(Omega*t-delta) + C*cos(Omega*t - delta)*1/(2*M), t)
tn =
Empty sym: 0-by-1
Computers don't always see the obvious, at least, not what we think of as obvious.
6 件のコメント
IN KWON PARK
2017 年 12 月 26 日
John D'Errico
2017 年 12 月 26 日
I'm a bit surprised why you got a result, while MATLAB just refuses to generate that result for me.
Part of me wants to substitute that solution into your equation and see if it reduces to zero. But that log term seems like it would be a problem.
As I showed, if you do divide by cos, then convert to a tangent, it does give the same solution. Sometimes symbolic solvers need a broad "hint" like that to get a solution in a form you want to see.
Even if I write it as:
tn=solve(sin(Omega*t-delta)/cos(Omega*t-delta) + C/(2*M)/Omega,t)
tn =
Empty sym: 0-by-1
Solve fails to see your solution. But if I convert to a tangent, then solve is happy, as you would expect.
IN KWON PARK
2017 年 12 月 26 日
Walter Roberson
2017 年 12 月 26 日
In R2017b with OS-X I get the two solutions that IN KWON PARK gets.
John, is it possible that you had a symbolic variable with assumptions sitting around in your workspace?
John D'Errico
2017 年 12 月 27 日
編集済み: John D'Errico
2017 年 12 月 27 日
No.
R2017b. OSX (10.13.2)
clear
syms Omega t delta C M
tn=solve(Omega*sin(Omega*t-delta) + C*cos(Omega*t - delta)*1/(2*M), t)
tn =
Empty sym: 0-by-1
Walter Roberson
2017 年 12 月 27 日
Odd -- also OS X, 2017b. Though I am running El Capitan rather than High Sierra
clear
syms Omega t delta C M
tn=solve(Omega*sin(Omega*t-delta) + C*cos(Omega*t - delta)*1/(2*M), t)
tn =
(delta + log((- C^2 - 4*M^2*Omega^2)^(1/2)/(C + M*Omega*2i))*1i)/Omega
(delta + log(-(- C^2 - 4*M^2*Omega^2)^(1/2)/(C + M*Omega*2i))*1i)/Omega
Note: if you did have an assumption it would have been saved with the symbolic engine, not at the MATLAB level. https://www.mathworks.com/help/symbolic/clear-assumptions-and-reset-the-symbolic-engine.html
reset(symengine)
カテゴリ
ヘルプ センター および File Exchange で Code Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!