How to find the roots of a trigonometric equation?

조회 수: 29 (최근 30일)
raha ahmadi
raha ahmadi 2022년 1월 10일
댓글: raha ahmadi 2022년 1월 11일
Hi, I want to determine the roots of a trigonometric equation :
, e and \theta_c are constant.
I try with 3 methods:
by Method 1, I got logarithmic answer. In Method 2, I got only one answer while I need more (I expended the length of the domain but nothing happend). and by Method 3 which Star Strider helped me alot, when I check the calculation and substitute the roots in equation I got nonzero answer (in that problem I did not have this error). I really appreciate any help.
L=1e-3;
f=-35;
e=sqrt(2/L-f^2);
pp=20;
l1=fplot(@(gammaL)e*sin(gammaL),[-pp,pp],'c');
hold on
l2=fplot(@(gammaL)-f*cos(gammaL));
figure
l3=fplot(@(gammaL)(e*sin(gammaL)+f*cos(gammaL)),[-pp,pp]);
zxi = find(diff(sign(l3.YData)));
for k = 1:numel(zxi)
idxrng = (-1:1)+zxi(k); % Index Range For Interpolation
if idxrng~=0
gammaL(k,:) = interp1(l3.YData(idxrng), l3.XData(idxrng), 0);
end
end
Thanks in advance
  댓글 수: 2
David Goodmanson
David Goodmanson 2022년 1월 10일
편집: David Goodmanson 2022년 1월 10일
Hi raha,
is this the correct equation? The solution is simply gammaL= atan( -theta_c /e ) + n*pi, where n is any integer.
raha ahmadi
raha ahmadi 2022년 1월 10일

Hi,thanks for your response. In fact I simplified the equation.My problem is why three different methods get three different answers. How I can be sure about complex problems. Also I think the Star Strider´code is exelent. Why I got solution with errors. Thanks again for your considration

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2022년 1월 10일
편집: John D'Errico 2022년 1월 10일
Solving for the roots of the trigonometric equation you show in youer question is actually trivial. Sorry, but it is. In fact, it can be done with pencil and paper, if you use a simple identity from trig.
You claim to have the problem:
e*sin(gammaL) + thetaC*cos(gammaL) == 0
where e and thetaC are known. Jut rewrite it as
-thetaC/e = sin(gammaL)/cos(gammaL)
Now if you recognize the right hand side as the tangent, we have
tan(gammaL) = -thetac/e
and therefore, the principle solution is just
gammaL = atan(-thetac/e)
if you want to solve for ALL solutions, remember that the tangent function is periodic, with period pi. so the fully general solution should be just
gammaL = atan(-thetac/e) + k*pi
where k is any integer. This should be valid as long as thetaC is not zero, and as long as cos(gammaL) is not zero. And as long as I am awake when I write this. :)
See what syms says now..
syms e thetaC gammaL
sol = solve(e*sin(gammaL) + thetaC*cos(gammaL) == 0,gammaL,'returnconditions',true)
sol = struct with fields:
gammaL: [2×1 sym] parameters: k conditions: [2×1 sym]
sol.gammaL
ans = 
sol.conditions
ans = 
So, is this a valid solution? Is it mathematically equivalent to my solution? Actually, yes. It must be so. That the symbolic toolbox did not see the simplification I found is not that important. You asked for a solution, did you not?
The symbolic toolbox saw that we can transform the problem using the identity
sin(u+v) = sin(u)cos(v) + cos(u)sin(v)
then it used deMoivre's identiy
exp(i*theta) = cos(theta) + i*sin(theta)
to solve for gammaL.
Both solutions should be equally valid, just expressed differently. For example:
e = 1; thetaC = 2;
vpa(subs(sol.gammaL),5)
ans = 
syms K
vpa(atan(-thetaC/e)) + K*pi
ans = 
Both solutions will come out of there, depending on if K is even or odd. With some mental effort, I could surely prove they were mathematically equivalent, but is there a good reason to do so?
  댓글 수: 3
John D'Errico
John D'Errico 2022년 1월 10일
We do not know exactly how solve achieves its magic. MathWorks does not distribute their code for a tool like that, and it can easily change in some future release. And the exact flowchart for how solve works will be quite complicated I am very sure.
But typically, a tool like solve tries different approaches, much like I might. I might look to see if I can get the problem into a simple form that I know how to solve. So I'll try a few things, then when one works, I am happy. Solve does the same sort of thing, except that solve is never truly going to be happy. (Computer programs lead such boring lives.)
As I said, it appears that solve apparently tried using a double angle identity, then it saw that deMoivre applies, so a solution can drop out by use of a natural log. In my personal solution, I followed a different path.
Is one analytical solution better than the other? Not really, although one must be care with a solution that produces complex results with an effectively zero imaginary part. Now you want to look to see how large is the imaginary part.
Is one solution method more accurate? I'm not sure what that means. If both approaches yield a valid solution, then they are both correct. One must always be careful of course with analytical solutions as I used. If you will divide by cos(thetaC), then you need to know that cos(thetaC) will never be zero, else you have now caused a problem due to the singularity.
If you used a numerical solver to find a solution, but in another approach, an analytical solution is found, then the numerical solver is never any better than the convergence tolerances applied. So one would generally prefer the analytical solution. If you are comparing two numerical methods, both of whch find subtly different solutions, asking which is more correct will depend on the tolerances for each method employed. It will depend on the methods used. You can compare the solutions found. How accurately do the various solutions found yield solutions to the original problems? Substitute the results into your equations. Do you get zero out? If not, then how far off from zero do you get? Which one is closer to zero?
Really, this is almost coming down to wanting to summarize a complete course on numerical analysis and numerical methods in not much more than one paragraph. (ok, one comment.) I can't do that.
In the end, you may be best off sitting down with a mathematician who understands numerical methods, and has a few minutes to help you. Show them your problem, not necessarily the ocde you used to try to solve it, as that only confuses things, since I think you are also a little confused here. Explain what you need to do. (Don't send me mail, as I won't do e-mail consulting.)
raha ahmadi
raha ahmadi 2022년 1월 11일
Thank you John D'Errico for your detailed explanation. You are right I should raise my numerical calculation skills or consult with mathematition. I like learn the optimum method for every equation. I try to learn asap.
thanks again and hope you all the best. you care alot and I really appreciate. (I agree with you, consulting publically is the best, these can be usefull for many people)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

VIGNESH B S
VIGNESH B S 2022년 1월 10일
syms e x t_c
eqn = e.*cos(x) + t_c.*cos(x) == 0;
solve(eqn,x)
here gamma*L = x
t_c - theta c
solve(equation , varaiable) and variable here is x = gamma*L.
  댓글 수: 1
raha ahmadi
raha ahmadi 2022년 1월 10일

Thank you VIGNESH B S.I tried your way too but I think I got logaritmic answer.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by