From: Imran on
Dear All
Good day
I have to find solution to following two equations

L1 Cos (theta1)+ L2 Cos (theta2)=x
L1 Sin (theta1) + L2 Sin (theta2)=y
here L1, L2, x and y are known

is there any direct function available?

best regards,
imran
From: Rune Allnor on
On 12 apr, 12:12, "Imran " <imran.sh...(a)gmail.com> wrote:
> Dear All
> Good day
> I have to find solution to following two equations
>
> L1 Cos (theta1)+ L2 Cos (theta2)=x
> L1 Sin (theta1) + L2 Sin (theta2)=y
> here L1, L2, x and y are known
>
> is there any direct function available?

Depends on what you want to solve for. If you are happy to
find the cosines and sines (as opposed to the angles) all
you need to do is to add the constraints

cos(theta1)^2 + sin(theta1)^2 = 1
cos(theta2)^2 + sin(theta2)^2 = 1

in which case you will end up with four equations in four
unknowns, which are easily solved.

If you want to find the angles theta1 and theta2 you have
trouble, as the inverse sines and cosine functions are ambiguous.

Rune
From: Imran on
Dear Rune
thanks for your reply
in fact i want to find the thetas! not their sin or cosine
regards,
Imran
Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <9232e424-2373-46c9-95e4-b6c24ba9c71c(a)i25g2000yqm.googlegroups.com>...
> On 12 apr, 12:12, "Imran " <imran.sh...(a)gmail.com> wrote:
> > Dear All
> > Good day
> > I have to find solution to following two equations
> >
> > L1 Cos (theta1)+ L2 Cos (theta2)=x
> > L1 Sin (theta1) + L2 Sin (theta2)=y
> > here L1, L2, x and y are known
> >
> > is there any direct function available?
>
> Depends on what you want to solve for. If you are happy to
> find the cosines and sines (as opposed to the angles) all
> you need to do is to add the constraints
>
> cos(theta1)^2 + sin(theta1)^2 = 1
> cos(theta2)^2 + sin(theta2)^2 = 1
>
> in which case you will end up with four equations in four
> unknowns, which are easily solved.
>
> If you want to find the angles theta1 and theta2 you have
> trouble, as the inverse sines and cosine functions are ambiguous.
>
> Rune
From: Roger Stafford on
"Imran " <imran.shafi(a)gmail.com> wrote in message <hpurlj$g9g$1(a)fred.mathworks.com>...
> Dear All
> Good day
> I have to find solution to following two equations
>
> L1 Cos (theta1)+ L2 Cos (theta2)=x
> L1 Sin (theta1) + L2 Sin (theta2)=y
> here L1, L2, x and y are known
>
> is there any direct function available?
>
> best regards,
> imran

Do the following:

L3 = sqrt(x^2+y^2);
theta3 = atan2(y,x);
theta1 = theta3 +/- acos((L3^2+L1^2-L2^2)/(2*L1*L3));
theta2 = theta3 +/- acos((L3^2+L2^2-L1^2)/(2*L2*L3));

The "+/-" designation above means that you need to try all four combinations of signs at these two places, testing each of the four resulting possible solutions in the original equations. Two of the solutions may be valid, or the arguments of the acos's could be out of range with no solution possible. This depends on the values of the quantities, L1, L2, x, and y that are given. Also the theta's in successful solutions may lie outside the range from -pi to +pi, in which case you are free to add or subtract multiples of 2*pi to them if you choose.

I leave it as "an exercise for the student" to discover the reasoning involved here. While you are doing this you may also discover a simpler criterion for choosing the unknown signs above.

Roger Stafford
From: Imran on
thank you very much Roger
I shall try it out and be back soon
Imran
"Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hpv7ip$ett$1(a)fred.mathworks.com>...
> "Imran " <imran.shafi(a)gmail.com> wrote in message <hpurlj$g9g$1(a)fred.mathworks.com>...
> > Dear All
> > Good day
> > I have to find solution to following two equations
> >
> > L1 Cos (theta1)+ L2 Cos (theta2)=x
> > L1 Sin (theta1) + L2 Sin (theta2)=y
> > here L1, L2, x and y are known
> >
> > is there any direct function available?
> >
> > best regards,
> > imran
>
> Do the following:
>
> L3 = sqrt(x^2+y^2);
> theta3 = atan2(y,x);
> theta1 = theta3 +/- acos((L3^2+L1^2-L2^2)/(2*L1*L3));
> theta2 = theta3 +/- acos((L3^2+L2^2-L1^2)/(2*L2*L3));
>
> The "+/-" designation above means that you need to try all four combinations of signs at these two places, testing each of the four resulting possible solutions in the original equations. Two of the solutions may be valid, or the arguments of the acos's could be out of range with no solution possible. This depends on the values of the quantities, L1, L2, x, and y that are given. Also the theta's in successful solutions may lie outside the range from -pi to +pi, in which case you are free to add or subtract multiples of 2*pi to them if you choose.
>
> I leave it as "an exercise for the student" to discover the reasoning involved here. While you are doing this you may also discover a simpler criterion for choosing the unknown signs above.
>
> Roger Stafford