Recall from trigonometry that the tangent of both pi/2 and - pi/2 is infinity. T
ID: 3812552 • Letter: R
Question
Recall from trigonometry that the tangent of both pi/2 and - pi/2 is infinity. This may be seen from the fact that tan(theta) = sin(theta)/cos(theta) and since sin(pi/2) = 1 and cos (pi/2) = 0 it follows that tan (pi/2) = infinity Because MATLAB uses a floating-point approximation of pi, it calculates the tangent of pi/2 as a very large number, but not infinity. Prompt the user to enter an angle theta between pi/2 and -pi/2, inclusive. If it is between pi/2 and -pi/2, but not equal to either of those values, calculate tan(theta) and display the result in the command window. If it is equal to pi/2 or -pi/2, set the result equal to Inf and display the result in the command window. If it is outside the specified range, send the user an error message in the command window and prompt the user to enter another value. Continue prompting the user for a new value of theta until he or she enters a valid number.Explanation / Answer
%matlab code
while true
angle = input('Enter an angle between pi/2 and -p1/2: ');
if angle == pi/2 || angle == (-1*pi/2)
disp('Inf');
elseif angle > pi/2 || angle < (-1*pi/2)
disp('Invalid Input');
else
fprintf('tan(%0.2f) = %0.2f ', angle, tan(angle));
break;
end
end
%{
output:
Enter an angle between pi/2 and -p1/2: -pi
Invalid Input
Enter an angle between pi/2 and -p1/2: pi/2
Inf
Enter an angle between pi/2 and -p1/2: pi/4
tan(0.79) = 1.00
%}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.