Using the solve function to find two angles

%a = fixed
%b = input
%c = input
%d = input
theta1 = [0:(1/180)*pi:2*pi];
for i = 1:361 syms theta2 theta4
eqn1 = a*cos(theta1(1,i)) + b*cos(theta2) - c - d*cos(theta4) == 0;
eqn2 = a*sin(theta1(1,i)) + b*sin(theta2) - c - d*sin(theta4) == 0;
sol = solve([eqn1,eqn2],[theta2,theta4]);
theta2Sol = (sol.theta2/pi)*180
theta4Sol = sol.theta4;
end
but the angles keep ending up as -(360*atan(102692670702549213410139403465476252652214531027842517147110598871^(1/2)/1309425174537674753319526986678195 - 173509832707425326512723168591872/436475058179224917773175662226065))/pi (360*atan(102692670702549213410139403465476252652214531027842517147110598871^(1/2)/1309425174537674753319526986678195 + 173509832707425326512723168591872/436475058179224917773175662226065))/pi
there does not seem to be an issue with the inputs

Réponses (1)

David Goodmanson
David Goodmanson le 28 Juil 2017
Modifié(e) : David Goodmanson le 28 Juil 2017
Hi s,
When the angles are real, there are two solutions to these equations.
S = 1 % the second set of solutions has S = -1
x = c*(1+i) -a*exp(i*th1);
th42 = S*acos((abs(x).^2-b^2-d^2)/(-2*b*d)); % th(4)-th(2)
th2 = angle(x./(b-d*exp(i*th42)));
th4 = th2 + th42;
This follows from the complex form of the two equations:
b*exp(i*th2) -d*exp(i*th4) = c*(1+i) - a*exp(i*th1)
You could combine all of this into a symbolic expression, or you could bypass symbolic, make this into a function and feed it a vector of angles th1. The resulting angles are real when the expressions are geometrically possible, complex if not.

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by