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:
Equations depicting 2 DOF

Subject: Equations depicting 2 DOF

From: imran

Date: 12 Apr, 2010 10:12:03

Message: 1 of 9

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

Subject: Equations depicting 2 DOF

From: Rune Allnor

Date: 12 Apr, 2010 11:24:22

Message: 2 of 9

On 12 apr, 12:12, "Imran " <imran.sh...@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

Subject: Equations depicting 2 DOF

From: imran

Date: 12 Apr, 2010 12:42:05

Message: 3 of 9

Dear Rune
thanks for your reply
in fact i want to find the thetas! not their sin or cosine
regards,
Imran
Rune Allnor <allnor@tele.ntnu.no> wrote in message <9232e424-2373-46c9-95e4-b6c24ba9c71c@i25g2000yqm.googlegroups.com>...
> On 12 apr, 12:12, "Imran " <imran.sh...@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

Subject: Equations depicting 2 DOF

From: Roger Stafford

Date: 12 Apr, 2010 13:35:21

Message: 4 of 9

"Imran " <imran.shafi@gmail.com> wrote in message <hpurlj$g9g$1@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

Subject: Equations depicting 2 DOF

From: imran

Date: 12 Apr, 2010 14:56:05

Message: 5 of 9

thank you very much Roger
I shall try it out and be back soon
Imran
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hpv7ip$ett$1@fred.mathworks.com>...
> "Imran " <imran.shafi@gmail.com> wrote in message <hpurlj$g9g$1@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

Subject: Equations depicting 2 DOF

From: imran

Date: 12 Apr, 2010 16:27:04

Message: 6 of 9

I am sorry to bother you again but Roger
but once i tried to solve the two equations mutually i get a little different outcome, please correct me where i am wrong
L1 Cos (theta1)+ L2 Cos (theta2)=x
L1 Sin (theta1) + L2 Sin (theta2)=y
squaring both sides and adding give me
cos (theta1-theta2)=(L3^2 - L1^2 - L2^2)/(2* L1 *L2), here i am stuck up
IN FACT how
theta1 = theta3 +/- acos((L3^2+L1^2-L2^2)/(2*L1*L3)); please if you can explain
Imran

"Imran " <imran.shafi@gmail.com> wrote in message <hpvca5$7i4$1@fred.mathworks.com>...
> thank you very much Roger
> I shall try it out and be back soon
> Imran
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hpv7ip$ett$1@fred.mathworks.com>...
> > "Imran " <imran.shafi@gmail.com> wrote in message <hpurlj$g9g$1@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

Subject: Equations depicting 2 DOF

From: Roger Stafford

Date: 12 Apr, 2010 19:16:05

Message: 7 of 9

"Imran " <imran.shafi@gmail.com> wrote in message <hpvhko$ri4$1@fred.mathworks.com>...
> I am sorry to bother you again but Roger
> but once i tried to solve the two equations mutually i get a little different outcome, please correct me where i am wrong
> L1 Cos (theta1)+ L2 Cos (theta2)=x
> L1 Sin (theta1) + L2 Sin (theta2)=y
> squaring both sides and adding give me
> cos (theta1-theta2)=(L3^2 - L1^2 - L2^2)/(2* L1 *L2), here i am stuck up
> IN FACT how
> theta1 = theta3 +/- acos((L3^2+L1^2-L2^2)/(2*L1*L3)); please if you can explain
> Imran
-------------------
  You almost have it, Imran! With the steps

 L3 = sqrt(x^2+y^2);
 theta3 = atan2(y,x);

the equations become

 L1*cos(theta1)+L2*cos(theta2) = L3*cos(theta3)
 L1*sin(theta1)+L2*sin(theta2) = L3*sin(theta3)

as you may have realized. On the next step instead of squaring these as they stand and adding, try transposing the two terms containing 'L2' to the right sides of the equations and then squaring and adding. What do you get? As I say, you're almost there.

Roger Stafford

Subject: Equations depicting 2 DOF

From: Roger Stafford

Date: 12 Apr, 2010 23:58:04

Message: 8 of 9

"Imran " <imran.shafi@gmail.com> wrote in message <hpurlj$g9g$1@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
------------------
  Imran, there is another more convenient answer to your problem that avoids the inconvenience of getting mismatched pairs of theta1 and theta2 solutions. I should have given it to begin with. It is also somewhat more intuitively evident.

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

  If a solution exists, this will be one. If the sign of the 's' quantity above is reversed, another valid solution is also produced.

  If L1, L2,and L3 are all positive quantities, this problem can be interpreted as one involving a triangle with sides L1, L2, and L3. One end of the L3 side is at the origin (0,0) and the other end at (x,y), which are two vertices of the triangle. The side L1 begins at (0,0), the side L2 begins at (x,y), and they must meet at a third vertex of the triangle. What angles theta1 and theta2 must the sides L1 and L2 make with respect to the x-axis?

  The above matlab code is a solution to that problem, except that it has allowed for possibly negative values for L1 and L2. It reveals the geometrical significance of having two solutions in some circumstances and none in others.

Roger Stafford

Subject: Equations depicting 2 DOF

From: imran

Date: 13 Apr, 2010 11:29:21

Message: 9 of 9

thanks Roger
you r genius
I am really obliged for your kind effort
warmest regards,
Imran

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hq0c2c$cbq$1@fred.mathworks.com>...
> "Imran " <imran.shafi@gmail.com> wrote in message <hpurlj$g9g$1@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
> ------------------
> Imran, there is another more convenient answer to your problem that avoids the inconvenience of getting mismatched pairs of theta1 and theta2 solutions. I should have given it to begin with. It is also somewhat more intuitively evident.
>
> theta3 = atan2(y,x);
> L3 = sqrt(x^2+y^2);
> s = sqrt((L1+L2+L3)*(L1+L2-L3)*(L1-L2+L3)*(-L1+L2+L3));
> theta1 = theta3 + atan2( s/L1,(L3^2+L1^2-L2^2)/L1);
> theta2 = theta3 + atan2(-s/L2,(L3^2-L1^2+L2^2)/L2);
>
> If a solution exists, this will be one. If the sign of the 's' quantity above is reversed, another valid solution is also produced.
>
> If L1, L2,and L3 are all positive quantities, this problem can be interpreted as one involving a triangle with sides L1, L2, and L3. One end of the L3 side is at the origin (0,0) and the other end at (x,y), which are two vertices of the triangle. The side L1 begins at (0,0), the side L2 begins at (x,y), and they must meet at a third vertex of the triangle. What angles theta1 and theta2 must the sides L1 and L2 make with respect to the x-axis?
>
> The above matlab code is a solution to that problem, except that it has allowed for possibly negative values for L1 and L2. It reveals the geometrical significance of having two solutions in some circumstances and none in others.
>
> 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