Inverse tangent inaccuracy?
3 views (last 30 days)
Show older comments
Robert Waechter
on 4 Nov 2017
Commented: Robert Waechter
on 4 Nov 2017
I wrote a program to calculate the open and crossed angle values of a four bar mechanism and everything seems to work fine until I get to the final calculation in which I try to take the inverse tangent of the quadratic equation and the resulting answers are incorrect. Here is my code.
L1=6;
L2=2;
L3=7;
L4=9;
theta2=30*(pi/180);
a=L2;
b=L3;
c=L4;
d=L1;
K1=d/a;
K2=d/c;
K3=(a^2-b^2+c^2+d^2)/(2*a*c);
K4=d/b;
K5=(c^2-d^2-a^2-b^2)/(2*a*b);
A=cos(theta2)-K1-(K2*cos(theta2))+K3;
B=-2*sin(theta2);
C=K1-((K2+1)*cos(theta2))+K3;
D=cos(theta2)-K1+(K4*cos(theta2))+K5;
E=B;
F=K1+((K4-1)*cos(theta2))+K5;
theta4a=2*(atand(-B+sqrt((B^2)-(4*A*C))/(2*A)))
theta4b=2*(atand(-B-sqrt((B^2)-(4*A*C))/(2*A)))
theta3a=2*(atand(-E+sqrt((E^2)-(4*D*F))/(2*D)))
theta3b=2*(atand(-E-sqrt((E^2)-(4*D*F))/(2*D)))
The values I get for answers are:
theta4a = -106.6958
theta4b = 146.7016
theta3a = -31.0711
theta3b = 132.5987
The resulting correct answers should be:
theta4a = -143.67
theta4b = 117.32
theta3a = -115.21
theta3b = 88.84
I can't seem to find the problem any help would be appreciated. Thanx!
0 Comments
Accepted Answer
David Goodmanson
on 4 Nov 2017
Hi Robert,
All you need do is replace the expression for theta4a by
theta4a = 2*atand((-B +sqrt((B^2)-(4*A*C)))/(2*A))
and similarly for the other three. You forgot that 2A divides -B as well as the sqrt term.
More Answers (0)
See Also
Categories
Find more on Fluid Dynamics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!