Prev: Conditional sampling from multivariate normal distribution
Next: How to transform equations in matrix form?
From: Imran on 12 Apr 2010 12:27 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(a)gmail.com> wrote in message <hpvca5$7i4$1(a)fred.mathworks.com>... > 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
From: Roger Stafford on 12 Apr 2010 15:16 "Imran " <imran.shafi(a)gmail.com> wrote in message <hpvhko$ri4$1(a)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
From: Roger Stafford on 12 Apr 2010 19:58 "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 ------------------ 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
From: Imran on 13 Apr 2010 07:29 thanks Roger you r genius I am really obliged for your kind effort warmest regards, Imran "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hq0c2c$cbq$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 > ------------------ > 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
First
|
Prev
|
Pages: 1 2 Prev: Conditional sampling from multivariate normal distribution Next: How to transform equations in matrix form? |