Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to solve simultaneous trigonometric equation

Subject: how to solve simultaneous trigonometric equation

From: rohit

Date: 25 Sep, 2010 11:35:25

Message: 1 of 13

Dear all,

I have two trigonometric equations of the form

a*sin(X) + b*sin(Y) = constant1

a*cos(X) + b*cos(Y) = constant2

Is there any way in Matlab to solve these two

thanks

Rohit

Subject: how to solve simultaneous trigonometric equation

From: Walter Roberson

Date: 25 Sep, 2010 15:08:12

Message: 2 of 13

On 25/09/10 6:35 AM, rohit wrote:

> I have two trigonometric equations of the form
>
> a*sin(X) + b*sin(Y) = constant1
>
> a*cos(X) + b*cos(Y) = constant2
> Is there any way in Matlab to solve these two
> thanks

The symbolic toolbox could probably solve this, but you need to define
which variables you are solving _for_ . Are you trying to find a and b,
or X and Y ? a and b are trivial to solve for, X and Y have messier
solutions.

Subject: how to solve simultaneous trigonometric equation

From: Roger Stafford

Date: 25 Sep, 2010 18:55:10

Message: 3 of 13

"rohit " <rohitnarula19@gmail.com> wrote in message <i7kmps$b78$1@fred.mathworks.com>...
> Dear all,
>
> I have two trigonometric equations of the form
>
> a*sin(X) + b*sin(Y) = constant1
>
> a*cos(X) + b*cos(Y) = constant2
>
> Is there any way in Matlab to solve these two
>
> thanks
>
> Rohit
- - - - - - - - -
  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.

  You are trying to solve

 a*sin(x) + b*sin(y) = c
 a*cos(x) + b*cos(y) = d

(where I have renamed the two constants on the right hand side.)

Define u = (x+y)/2 and v = (x-y)/2, so that x = u+v and y = u-v. Hence

 a*sin(u+v) + b*sin(u-v) = c
 a*cos(u+v) + b*cos(u-v) = d

which can be expanded and combined to

 (a+b)*sin(u)*cos(v) + (a-b)*cos(u)*sin(v) = c
 (a+b)*cos(u)*cos(v) - (a-b)*sin(u)*sin(v) = d

By combining these as indicated by the right hand sides of the following we get

 (a+b)*cos(v) = c*sin(u) + d*cos(u)
 (a-b)*sin(v) = c*cos(u) - d*sin(u)

The angle t = atan2(c,d) satisfies the equations

 c = r*sin(t)
 d = r*cos(t)

where r = sqrt(c^2+d^2) and this gives us the equations

 (a+b)*cos(v) = r*cos(t-u)
 (a-b)*sin(v) = r*sin(t-u)

If we square both sides and add, this eliminates t-u and we have an equation containing only v:

 4*a*b*cos(v)^2 + (a-b)^2 = r^2

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 t-u. From there you can find your way back to solutions for x and y.

  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 single-expression answer.

Roger Stafford

Subject: how to solve simultaneous trigonometric equation

From: Walter Roberson

Date: 25 Sep, 2010 19:32:37

Message: 4 of 13

On 25/09/10 1:55 PM, Roger Stafford wrote:
> "rohit " <rohitnarula19@gmail.com> wrote in message

>> a*sin(X) + b*sin(Y) = constant1
>> a*cos(X) + b*cos(Y) = constant2

> If we square both sides and add, this eliminates t-u and we have an
> equation containing only v:
>
> 4*a*b*cos(v)^2 + (a-b)^2 = r^2
>
> which can be solved for v. There will in general be four different
> solutions within the range from -pi to +pi.

Maple's direct solution for X and Y is indeed rather messy in detail
(though not in form.) Maple only finds two solution forms, though.

Subject: how to solve simultaneous trigonometric equation

From: Roger Stafford

Date: 25 Sep, 2010 19:47:22

Message: 5 of 13

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i7lgie$a4$1@fred.mathworks.com>...
> ........
> 4*a*b*cos(v)^2 + (a-b)^2 = r^2
>
> which can be solved for v. There will in general be four different solutions within the range from -pi to +pi.
> .......
- - - - - - -
  I should have added a bit more detail to the solution for v. The equation for v can be put in the two forms

 cos(v)^2 = (c^2+d^2-(a-b)^2)/(4*a*b)
 sin(v)^2 = ((a+b)^2-c^2-d^2)/(4*a*b)

which means the two right hand sides must each be non-negative, and this puts two constraints on the four constants, a, b, c, and d. If this is the case, we can say

 v = atan2(sqrt(((a+b)^2-c^2-d^2)/(4*a*b)), ...
           sqrt((c^2+d^2-(a-b)^2)/(4*a*b)));

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:

 pi-v, v-pi, and -v, (2nd, 3rd, & 4th quadrants, resp.)

to make a total of four solutions in the range -pi to +pi. Each of these will lead to a unique t-u value within the -pi to +pi range again via the atan2 function.

Roger Stafford

Subject: how to solve simultaneous trigonometric equation

From: Roger Stafford

Date: 25 Sep, 2010 20:27:08

Message: 6 of 13

Walter Roberson <roberson@hushmail.com> wrote in message <p7sno.4474$ez6.2031@newsfe02.iad>...
> Maple only finds two solution forms, though.
- - - - - - -
  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 = u-v in that range as those in the first two quadrants.

Roger Stafford

Subject: how to solve simultaneous trigonometric equation

From: Greg Heath

Date: 25 Sep, 2010 20:45:07

Message: 7 of 13

On Sep 25, 7:35 am, "rohit " <rohitnarul...@gmail.com> wrote:
> Dear all,
>
> I have two trigonometric equations of the form
>
> a*sin(X) + b*sin(Y) = constant1
>
> a*cos(X) + b*cos(Y) = constant2
>
> Is there any way in Matlab to solve these two

With the substitutions

U = sin(X), V = cos(Y)

You can obtain a linear relationship between
U and V and a quadratic equation for either.

The quadratic will give you two solutions
and the inverse sin or cos will boost it
up to four.

I guess you'll have to go back to the original
equations toget the right signs/quadrants.

Hope this helps.

Greg

Subject: how to solve simultaneous trigonometric equation

From: Bruno Luong

Date: 25 Sep, 2010 21:20:28

Message: 8 of 13


>
> a*sin(X) + b*sin(Y) = constant1 (eqt1)
>
> a*cos(X) + b*cos(Y) = constant2 (eqt2)
>

(2)+i*(1) and (2)-i*(1) gives

a*exp(iX) + b*exp(iY) = z1
a*exp(-iX) + b*exp(-iY) = z2

With z1 = constant2 + i*constant1, z2 = conj(z)

Let's change the variable to u = exp(iX) and v = = exp(iY), we get:

a*u + b*v = z1 (eqt3)
a/u + b/v = z2 (eqt4)

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.

Bruno

Subject: how to solve simultaneous trigonometric equation

From: Roger Stafford

Date: 25 Sep, 2010 23:13:04

Message: 9 of 13

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i7lp2s$2i9$1@fred.mathworks.com>...
> > a*sin(X) + b*sin(Y) = constant1 (eqt1)
> > a*cos(X) + b*cos(Y) = constant2 (eqt2)
>
> (2)+i*(1) and (2)-i*(1) gives
>
> a*exp(iX) + b*exp(iY) = z1
> a*exp(-iX) + b*exp(-iY) = z2
>
> With z1 = constant2 + i*constant1, z2 = conj(z)
>
> Let's change the variable to u = exp(iX) and v = = exp(iY), we get:
>
> a*u + b*v = z1 (eqt3)
> a/u + b/v = z2 (eqt4)
>
> 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.
>
> Bruno
- - - - - - - - -
  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.

Roger Stafford

Subject: how to solve atan2() function

From: Parth

Date: 30 Jan, 2014 03:04:07

Message: 10 of 13

(a+b)*cos(v) = c*sin(u) + d*cos(u)
 (a-b)*sin(v) = c*cos(u) - d*sin(u)

The angle t = atan2(c,d) satisfies the equations

 c = r*sin(t)
 d = r*cos(t)

where r = sqrt(c^2+d^2) and this gives us the equations

 (a+b)*cos(v) = r*cos(t-u)
 (a-b)*sin(v) = r*sin(t-u).


can any one tell me how last two equations came using atan2() function????

Subject: how to solve atan2() function

From: Roger Stafford

Date: 30 Jan, 2014 16:40:10

Message: 11 of 13

"Parth" wrote in message <lccff7$3kg$1@newscl01ah.mathworks.com>...
> (a+b)*cos(v) = c*sin(u) + d*cos(u)
> (a-b)*sin(v) = c*cos(u) - d*sin(u)
>
> The angle t = atan2(c,d) satisfies the equations
>
> c = r*sin(t)
> d = r*cos(t)
>
> where r = sqrt(c^2+d^2) and this gives us the equations
>
> (a+b)*cos(v) = r*cos(t-u)
> (a-b)*sin(v) = r*sin(t-u).
>
>
> can any one tell me how last two equations came using atan2() function????
- - - - - - - -
  It is a fact that for any two quantities, c and d, one can always find values r and t such that

  c = r*sin(t)
  d = r*cos(t)

for -pi < t <= pi. The solution is:

  sqrt(c^2+d^2) = sqrt(r^2*sin(t)^2+r^2*cos(t)^2)) = sqrt(r^2*1) = r

and

  c/d = (r*sin(t))/(r*cos(t)) = tan(t)

and hence

  t = atan2(c,d).

  For those last two equations which you refer to, substitute the above expressions for c and d to get:

  (a+b)*cos(v) = c*sin(u) + d*cos(u)
               = r*sin(t)*sin(u) + r*cos(t)*cos(u)
               = r*(cos(t)*cos(u) + sin(t)*sin(u))
               = r*cos(t-u)
 
  (a-b)*sin(v) = c*cos(u) - d*sin(u)
               = r*sin(t)*cos(u) - r*cos(t)*sin(u)
               = r*(sin(t)*cos(u) - cos(t)*sin(u))
               = r*sin(t-u)

Roger Stafford

Subject: how to solve atan2() function

From: Parth

Date: 17 Feb, 2014 09:36:08

Message: 12 of 13

Dear all,

I have two equations,

L1*cos?1 + L2*cos?2 + E*cos?e = P AND L1*sin?1 + L2*sin?2 + E*cos?e = 0

How to solve these for ?1 & ?2, when L1, L2, E, P and ?e are known to me??

Thanks...

Subject: how to solve atan2() function

From: Roger Stafford

Date: 17 Feb, 2014 19:13:08

Message: 13 of 13

"Parth" wrote in message <ldsl68$4dq$1@newscl01ah.mathworks.com>...
> L1*cos?1 + L2*cos?2 + E*cos?e = P AND L1*sin?1 + L2*sin?2 + E*cos?e = 0
> How to solve these for ?1 & ?2, when L1, L2, E, P and ?e are known to me??
- - - - - - - - - -
  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.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us