Solving two trigonometric equations, two unknowns
조회 수: 11 (최근 30일)
이전 댓글 표시
Hello,
It's been a while since using Matlab. I've been trying to solve the following equations with no luck, lots of error messages. I've heard a lot of mention about Symbolic which I have not come across before either. I've had a search through the existing questions but the problems I've found haven''t related to the type of problem I have.
The equations are the loop equations for a simple linkage mechanism.
R*cos(x)-L1*cos(y)=L2*cos(p)
R*sin(x)-L1*sin(y)=L2*sin(p)
Where L1, L2, p are constants.
R is a known input
x and y are the angles I would like to find.
Does it start something like this after defining variables:
>> syms L1 L2 p R x y
The=solve(R*sin(x)-L1*sin(y)=L2*sin(p))
Any help would be greatly appreciated,
Mike
댓글 수: 0
채택된 답변
Roger Stafford
2013년 4월 4일
There is no need for the answer to be that complicated. Here is a method entirely independent of 'solve' and 'fsolve'.
R*cos(x)-L1*cos(y)=L2*cos(p)
R*sin(x)-L1*sin(y)=L2*sin(p)
L1*cos(y) = R*cos(x)-L2*cos(p)
L1*sin(y) = R*sin(x)-L2*sin(p)
Now square both sides of both equations and add them to get:
(L1*cos(y))^2+(L1*sin(y))^2 = (R*cos(x)-L2*cos(p))^2+(R*sin(x)-L2*sin(p))^2
L1^2 = R^2+L2^2-2*R*L2*(cos(x)*cos(p)+sin(x)*sin(p)) = R^2+L2^2-2*R*L2*cos(x-p)
cos(x-p) = (R^2+L2^2-L1^2)/(2*R*L2)
There are two solutions for x in the interval between -pi and +pi which can be obtained using matlab's 'acos' function (assuming the above argument is between -1 and +1). For each of these x values, a corresponding y can be found using matlab's 'atan2' function:
sin(y) = (R*sin(x)-L2*sin(p))/L1
cos(y) = (R*cos(x)-L2*cos(p))/L1
y = atan2((R*sin(x)-L2*sin(p))/L1,(R*cos(x)-L2*cos(p))/L1)
Thus there are two solutions for x and y lying within -pi to +pi. Any multiple of 2*pi can obviously be added or subtracted from either x or y for an infinitude of other possible solution pairs.
댓글 수: 6
추가 답변 (5개)
Sean de Wolski
2013년 4월 4일
syms L1 L2 p R x y
Result=solve(R*cos(x)-L1*cos(y)==L2*cos(p),...
R*sin(x)-L1*sin(y)==L2*sin(p),x,y)
Result.x
Result.y
댓글 수: 0
Mike Scott
2013년 4월 4일
편집: Walter Roberson
2013년 4월 6일
댓글 수: 1
Sean de Wolski
2013년 4월 4일
So it's working, the closed form solution is just ugly...
Try fsolve in the Optimization Toolbox to get a numerical answer instead. Or use subs() to plug in your values into the above expression and get you the values for x and y.
Walter Roberson
2013년 4월 15일
Two solutions, based upon two roots of a polynomial of degree 2. Angles are in radians.
x = arctan((-cos(p)*2^(1/2)*((L2+L1+R)*(R+L1-L2)*(R-L2-L1)*(L2-L1+R)*(-1+cos(2*p)))^(1/2)-(R^2-L1^2+L2^2)*(-1+cos(2*p)))/(R*L2*sin(p)), (2^(1/2)*((L2+L1+R)*(R+L1-L2)*(R-L2-L1)*(L2-L1+R)*(-1+cos(2*p)))^(1/2)+(2*R^2+2*L2^2-2*L1^2)*cos(p))/(R*L2)) y = arctan((-cos(p)*2^(1/2)*((L2+L1+R)*(R+L1-L2)*(R-L2-L1)*(L2-L1+R)*(-1+cos(2*p)))^(1/2)-(R^2-L1^2-L2^2)*(-1+cos(2*p)))/(L2*sin(p)*L1), (2^(1/2)*((L2+L1+R)*(R+L1-L2)*(R-L2-L1)*(L2-L1+R)*(-1+cos(2*p)))^(1/2)+(2*R^2-2*L2^2-2*L1^2)*cos(p))/(L1*L2))
x = arctan((cos(p)*2^(1/2)*((L2+L1+R)*(R+L1-L2)*(R-L2-L1)*(L2-L1+R)*(-1+cos(2*p)))^(1/2)-(R^2-L1^2+L2^2)*(-1+cos(2*p)))/(R*L2*sin(p)), (-2^(1/2)*((L2+L1+R)*(R+L1-L2)*(R-L2-L1)*(L2-L1+R)*(-1+cos(2*p)))^(1/2)+(2*R^2+2*L2^2-2*L1^2)*cos(p))/(R*L2)) y = arctan((cos(p)*2^(1/2)*((L2+L1+R)*(R+L1-L2)*(R-L2-L1)*(L2-L1+R)*(-1+cos(2*p)))^(1/2)-(R^2-L1^2-L2^2)*(-1+cos(2*p)))/(L2*sin(p)*L1), (-2^(1/2)*((L2+L1+R)*(R+L1-L2)*(R-L2-L1)*(L2-L1+R)*(-1+cos(2*p)))^(1/2)+(2*R^2-2*L2^2-2*L1^2)*cos(p))/(L1*L2))
The two pairs can be written more compactly using some temporary variables, as there are long common sub-expressions.
댓글 수: 0
ABHISHEK SARATH
2020년 3월 17일
syms a b c d phi thi beta
eq1=a*cos(thi)+b*cos(phi)-c*cos(phi)==d;%% equating real part
eq2=a*sin(thi)+b*sin(beta)-c*sin(phi)==0;%% equating imaginary part
s=solve([eq1,eq2],phi);
i am getting error like this
warning: Solutions are valid under the following conditions: (in((z - pi + asin((b*sin(beta) +
a*sin(thi))/c))/(2*pi), 'integer') | in((z - asin((b*sin(beta) + a*sin(thi))/c))/(2*pi), 'integer')) &
(in((z + acos((d - a*cos(thi))/(b - c)))/(2*pi), 'integer') | in((z - acos((d - a*cos(thi))/(b -
c)))/(2*pi), 'integer')). To include parameters and conditions in the solution, specify the
'ReturnConditions' value as 'true'.
댓글 수: 3
Walter Roberson
2020년 3월 21일
The process is similar to your Question
s=solve([eq1,eq2],phi, 'returnconditions', true);
>> pretty(s.conditions)
/ / d - a cos(thi) \ / d - a cos(thi) \ \
| z + acos| -------------- | z - acos| -------------- | |
/ z - pi + #1 z - #1 \ | \ b - c / \ b - c / |
| ----------- in integer or ------ in integer | and | -------------------------- in integer or -------------------------- in integer |
\ 2 pi 2 pi / \ 2 pi 2 pi /
where
/ b sin(beta) + a sin(thi) \
#1 == asin| ------------------------ |
\ c /
This tells you that you need to calculate that asin(), and that when you do, the solution you are looking for, phi, is the set of all values that are either an integer multiple of 2*pi more than the asin() or else an integer multiple of 2*pi, plus pi, more than the asin(), provided that the value also happens to be an integer multiple of 2*pi greater than +/- the acos() .
Those values are not guaranteed to exist at all.
You will probably not find this to be a very useful solution. You are trying to solve equations that have an infinite number of solutions if they have any solutions at all, and there is seldom explicit formulas for expressing an infinite number of solutions.
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!