http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359
MATLAB Central Newsreader  how to solve simultaneous trigonometric equation
Feed for thread: how to solve simultaneous trigonometric equation
enus
©19942017 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://nl.mathworks.com/images/membrane_icon.gif

Sat, 25 Sep 2010 11:35:25 +0000
how to solve simultaneous trigonometric equation
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#782475
rohit
Dear all,<br>
<br>
I have two trigonometric equations of the form<br>
<br>
a*sin(X) + b*sin(Y) = constant1<br>
<br>
a*cos(X) + b*cos(Y) = constant2 <br>
<br>
Is there any way in Matlab to solve these two <br>
<br>
thanks<br>
<br>
Rohit

Sat, 25 Sep 2010 15:08:12 +0000
Re: how to solve simultaneous trigonometric equation
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#782511
Walter Roberson
On 25/09/10 6:35 AM, rohit wrote:<br>
<br>
> I have two trigonometric equations of the form<br>
><br>
> a*sin(X) + b*sin(Y) = constant1<br>
><br>
> a*cos(X) + b*cos(Y) = constant2<br>
> Is there any way in Matlab to solve these two<br>
> thanks<br>
<br>
The symbolic toolbox could probably solve this, but you need to define <br>
which variables you are solving _for_ . Are you trying to find a and b, <br>
or X and Y ? a and b are trivial to solve for, X and Y have messier <br>
solutions.

Sat, 25 Sep 2010 18:55:10 +0000
Re: how to solve simultaneous trigonometric equation
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#782536
Roger Stafford
"rohit " <rohitnarula19@gmail.com> wrote in message <i7kmps$b78$1@fred.mathworks.com>...<br>
> Dear all,<br>
> <br>
> I have two trigonometric equations of the form<br>
> <br>
> a*sin(X) + b*sin(Y) = constant1<br>
> <br>
> a*cos(X) + b*cos(Y) = constant2 <br>
> <br>
> Is there any way in Matlab to solve these two <br>
> <br>
> thanks<br>
> <br>
> Rohit<br>
        <br>
As Walter suggests, the symbolic toolbox can provide you with a solution. However, it comes in a complicated form that is not very intuitive which is caused by having to give the solution as a single expression. I much prefer to do this kind of problem by hand if possible, and the solution in this case is much easier (at least for me) to comprehend. I will give you only an outline of the reasoning involved.<br>
<br>
You are trying to solve<br>
<br>
a*sin(x) + b*sin(y) = c<br>
a*cos(x) + b*cos(y) = d<br>
<br>
(where I have renamed the two constants on the right hand side.)<br>
<br>
Define u = (x+y)/2 and v = (xy)/2, so that x = u+v and y = uv. Hence<br>
<br>
a*sin(u+v) + b*sin(uv) = c<br>
a*cos(u+v) + b*cos(uv) = d<br>
<br>
which can be expanded and combined to<br>
<br>
(a+b)*sin(u)*cos(v) + (ab)*cos(u)*sin(v) = c<br>
(a+b)*cos(u)*cos(v)  (ab)*sin(u)*sin(v) = d<br>
<br>
By combining these as indicated by the right hand sides of the following we get<br>
<br>
(a+b)*cos(v) = c*sin(u) + d*cos(u)<br>
(ab)*sin(v) = c*cos(u)  d*sin(u)<br>
<br>
The angle t = atan2(c,d) satisfies the equations<br>
<br>
c = r*sin(t)<br>
d = r*cos(t)<br>
<br>
where r = sqrt(c^2+d^2) and this gives us the equations<br>
<br>
(a+b)*cos(v) = r*cos(tu)<br>
(ab)*sin(v) = r*sin(tu)<br>
<br>
If we square both sides and add, this eliminates tu and we have an equation containing only v:<br>
<br>
4*a*b*cos(v)^2 + (ab)^2 = r^2<br>
<br>
which can be solved for v. There will in general be four different solutions within the range from pi to +pi. By substituting each of these into the above pair of equations, we can use atan2 to find corresponding solutions for tu. From there you can find your way back to solutions for x and y.<br>
<br>
This reasoning can actually be used to give steps in matlab for the solution that will very likely be more efficient, as well as easier to understand, than trying to reproduce the symbolic toolbox's awful singleexpression answer.<br>
<br>
Roger Stafford

Sat, 25 Sep 2010 19:32:37 +0000
Re: how to solve simultaneous trigonometric equation
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#782541
Walter Roberson
On 25/09/10 1:55 PM, Roger Stafford wrote:<br>
> "rohit " <rohitnarula19@gmail.com> wrote in message<br>
<br>
>> a*sin(X) + b*sin(Y) = constant1<br>
>> a*cos(X) + b*cos(Y) = constant2<br>
<br>
> If we square both sides and add, this eliminates tu and we have an<br>
> equation containing only v:<br>
><br>
> 4*a*b*cos(v)^2 + (ab)^2 = r^2<br>
><br>
> which can be solved for v. There will in general be four different<br>
> solutions within the range from pi to +pi.<br>
<br>
Maple's direct solution for X and Y is indeed rather messy in detail <br>
(though not in form.) Maple only finds two solution forms, though.

Sat, 25 Sep 2010 19:47:22 +0000
Re: how to solve simultaneous trigonometric equation
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#782547
Roger Stafford
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i7lgie$a4$1@fred.mathworks.com>...<br>
> ........<br>
> 4*a*b*cos(v)^2 + (ab)^2 = r^2<br>
> <br>
> which can be solved for v. There will in general be four different solutions within the range from pi to +pi. <br>
> .......<br>
      <br>
I should have added a bit more detail to the solution for v. The equation for v can be put in the two forms<br>
<br>
cos(v)^2 = (c^2+d^2(ab)^2)/(4*a*b)<br>
sin(v)^2 = ((a+b)^2c^2d^2)/(4*a*b)<br>
<br>
which means the two right hand sides must each be nonnegative, and this puts two constraints on the four constants, a, b, c, and d. If this is the case, we can say<br>
<br>
v = atan2(sqrt(((a+b)^2c^2d^2)/(4*a*b)), ...<br>
sqrt((c^2+d^2(ab)^2)/(4*a*b)));<br>
<br>
which gives a solution in the first quadrant and then append to this the values in the other three quadrants which would also be valid:<br>
<br>
piv, vpi, and v, (2nd, 3rd, & 4th quadrants, resp.)<br>
<br>
to make a total of four solutions in the range pi to +pi. Each of these will lead to a unique tu value within the pi to +pi range again via the atan2 function.<br>
<br>
Roger Stafford

Sat, 25 Sep 2010 20:27:08 +0000
Re: how to solve simultaneous trigonometric equation
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#782554
Roger Stafford
Walter Roberson <roberson@hushmail.com> wrote in message <p7sno.4474$ez6.2031@newsfe02.iad>...<br>
> Maple only finds two solution forms, though.<br>
      <br>
Yes Walter, I think Maple is correct that there are only two solutions for x and y in the range pi to +pi. The 3rd and 4th quadrant solutions for v lead to the same answers for x=u+v and y = uv in that range as those in the first two quadrants.<br>
<br>
Roger Stafford

Sat, 25 Sep 2010 20:45:07 +0000
Re: how to solve simultaneous trigonometric equation
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#782555
Greg Heath
On Sep 25, 7:35 am, "rohit " <rohitnarul...@gmail.com> wrote:<br>
> Dear all,<br>
><br>
> I have two trigonometric equations of the form<br>
><br>
> a*sin(X) + b*sin(Y) = constant1<br>
><br>
> a*cos(X) + b*cos(Y) = constant2<br>
><br>
> Is there any way in Matlab to solve these two<br>
<br>
With the substitutions<br>
<br>
U = sin(X), V = cos(Y)<br>
<br>
You can obtain a linear relationship between<br>
U and V and a quadratic equation for either.<br>
<br>
The quadratic will give you two solutions<br>
and the inverse sin or cos will boost it<br>
up to four.<br>
<br>
I guess you'll have to go back to the original<br>
equations toget the right signs/quadrants.<br>
<br>
Hope this helps.<br>
<br>
Greg

Sat, 25 Sep 2010 21:20:28 +0000
Re: how to solve simultaneous trigonometric equation
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#782559
Bruno Luong
<br>
> <br>
> a*sin(X) + b*sin(Y) = constant1 (eqt1)<br>
> <br>
> a*cos(X) + b*cos(Y) = constant2 (eqt2)<br>
> <br>
<br>
(2)+i*(1) and (2)i*(1) gives<br>
<br>
a*exp(iX) + b*exp(iY) = z1<br>
a*exp(iX) + b*exp(iY) = z2<br>
<br>
With z1 = constant2 + i*constant1, z2 = conj(z)<br>
<br>
Let's change the variable to u = exp(iX) and v = = exp(iY), we get:<br>
<br>
a*u + b*v = z1 (eqt3)<br>
a/u + b/v = z2 (eqt4)<br>
<br>
Replace u = z1/a  b/a*v in (eqt4), this gives a second order polynomial equation in v that can be solved with two solutions of v. From that, just go back and find out what is u, then x and y.<br>
<br>
Bruno

Sat, 25 Sep 2010 23:13:04 +0000
Re: how to solve simultaneous trigonometric equation
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#782574
Roger Stafford
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i7lp2s$2i9$1@fred.mathworks.com>...<br>
> > a*sin(X) + b*sin(Y) = constant1 (eqt1)<br>
> > a*cos(X) + b*cos(Y) = constant2 (eqt2)<br>
> <br>
> (2)+i*(1) and (2)i*(1) gives<br>
> <br>
> a*exp(iX) + b*exp(iY) = z1<br>
> a*exp(iX) + b*exp(iY) = z2<br>
> <br>
> With z1 = constant2 + i*constant1, z2 = conj(z)<br>
> <br>
> Let's change the variable to u = exp(iX) and v = = exp(iY), we get:<br>
> <br>
> a*u + b*v = z1 (eqt3)<br>
> a/u + b/v = z2 (eqt4)<br>
> <br>
> Replace u = z1/a  b/a*v in (eqt4), this gives a second order polynomial equation in v that can be solved with two solutions of v. From that, just go back and find out what is u, then x and y.<br>
> <br>
> Bruno<br>
        <br>
That's a good method, Bruno, easier to understand than mine. You would probably best use atan2 to go back from u and v to x and y. Presumably in solving the second order polynomial you would arrive at the same two constraints on the constants that I did.<br>
<br>
Roger Stafford

Thu, 30 Jan 2014 03:04:07 +0000
how to solve atan2() function
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#917159
Parth
(a+b)*cos(v) = c*sin(u) + d*cos(u)<br>
(ab)*sin(v) = c*cos(u)  d*sin(u)<br>
<br>
The angle t = atan2(c,d) satisfies the equations<br>
<br>
c = r*sin(t)<br>
d = r*cos(t)<br>
<br>
where r = sqrt(c^2+d^2) and this gives us the equations<br>
<br>
(a+b)*cos(v) = r*cos(tu)<br>
(ab)*sin(v) = r*sin(tu).<br>
<br>
<br>
can any one tell me how last two equations came using atan2() function????

Thu, 30 Jan 2014 16:40:10 +0000
Re: how to solve atan2() function
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#917190
Roger Stafford
"Parth" wrote in message <lccff7$3kg$1@newscl01ah.mathworks.com>...<br>
> (a+b)*cos(v) = c*sin(u) + d*cos(u)<br>
> (ab)*sin(v) = c*cos(u)  d*sin(u)<br>
> <br>
> The angle t = atan2(c,d) satisfies the equations<br>
> <br>
> c = r*sin(t)<br>
> d = r*cos(t)<br>
> <br>
> where r = sqrt(c^2+d^2) and this gives us the equations<br>
> <br>
> (a+b)*cos(v) = r*cos(tu)<br>
> (ab)*sin(v) = r*sin(tu).<br>
> <br>
> <br>
> can any one tell me how last two equations came using atan2() function????<br>
       <br>
It is a fact that for any two quantities, c and d, one can always find values r and t such that<br>
<br>
c = r*sin(t)<br>
d = r*cos(t)<br>
<br>
for pi < t <= pi. The solution is:<br>
<br>
sqrt(c^2+d^2) = sqrt(r^2*sin(t)^2+r^2*cos(t)^2)) = sqrt(r^2*1) = r<br>
<br>
and<br>
<br>
c/d = (r*sin(t))/(r*cos(t)) = tan(t)<br>
<br>
and hence<br>
<br>
t = atan2(c,d).<br>
<br>
For those last two equations which you refer to, substitute the above expressions for c and d to get:<br>
<br>
(a+b)*cos(v) = c*sin(u) + d*cos(u)<br>
= r*sin(t)*sin(u) + r*cos(t)*cos(u)<br>
= r*(cos(t)*cos(u) + sin(t)*sin(u))<br>
= r*cos(tu)<br>
<br>
(ab)*sin(v) = c*cos(u)  d*sin(u)<br>
= r*sin(t)*cos(u)  r*cos(t)*sin(u)<br>
= r*(sin(t)*cos(u)  cos(t)*sin(u))<br>
= r*sin(tu)<br>
<br>
Roger Stafford

Mon, 17 Feb 2014 09:36:08 +0000
Re: how to solve atan2() function
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#918238
Parth
Dear all,<br>
<br>
I have two equations,<br>
<br>
L1*cos?1 + L2*cos?2 + E*cos?e = P AND L1*sin?1 + L2*sin?2 + E*cos?e = 0<br>
<br>
How to solve these for ?1 & ?2, when L1, L2, E, P and ?e are known to me??<br>
<br>
Thanks...

Mon, 17 Feb 2014 19:13:08 +0000
Re: how to solve atan2() function
http://nl.mathworks.com/matlabcentral/newsreader/view_thread/292359#918264
Roger Stafford
"Parth" wrote in message <ldsl68$4dq$1@newscl01ah.mathworks.com>...<br>
> L1*cos?1 + L2*cos?2 + E*cos?e = P AND L1*sin?1 + L2*sin?2 + E*cos?e = 0<br>
> How to solve these for ?1 & ?2, when L1, L2, E, P and ?e are known to me??<br>
         <br>
Transpose E*cos?e to the right hand side in each equation and you have the equations in precisely the same form as with the first message in this thread, and they can be solved the same way as shown in subsequent messages. I'm sure you can do it yourself.<br>
<br>
Roger Stafford