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 件のコメント
ABHISHEK SARATH
2020 年 3 月 18 日
could u explain what does that z mean and what step should i take next
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!