How to find the roots of a trigonometric equation?

16 views (last 30 days)
raha ahmadi
raha ahmadi on 10 Jan 2022
Commented: raha ahmadi on 11 Jan 2022
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.
hold on
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);
Thanks in advance
raha ahmadi
raha ahmadi on 10 Jan 2022

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

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 10 Jan 2022
Edited: John D'Errico on 10 Jan 2022
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]
ans = 
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;
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?
raha ahmadi
raha ahmadi on 11 Jan 2022
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)

Sign in to comment.

More Answers (1)

VIGNESH B S on 10 Jan 2022
syms e x t_c
eqn = e.*cos(x) + t_c.*cos(x) == 0;
here gamma*L = x
t_c - theta c
solve(equation , varaiable) and variable here is x = gamma*L.
  1 Comment
raha ahmadi
raha ahmadi on 10 Jan 2022

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

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!

Translated by