t=theta The tangent function is defined as than (t)=sin(t)/cos(t). Thisexpressio
ID: 1821038 • Letter: T
Question
t=thetaThe tangent function is defined as than (t)=sin(t)/cos(t). Thisexpression can be evaluated to solve for the tangent as long as themagnitude of cos(t) is not too near to 0. Assume that (t) is givenin degrees, and write the matlab statement to evaluate tan (t) aslong as the magnitude of cos(t) is greater then or equal to(10^-20). If the magnitude of cos(t) less then (10^-10, write outan error message instead.
Explanation / Answer
function [output] = mytan(t); radianAngle = t*pi/180; % Convert the angle t to an angle inradians (I think the MatLab sin and cos functions require radianinputs) if (cos(radianAngle) >= 10^-10) output = sin(radianAngle)/cos(radianAngle); else disp('Error'); output = inf; % The tangent would be around infinite end end I haven't actually tested this code, so there might be someproblems with it, but hopefully you get the idea. You basicallycheck 'if' cos(angle) is large enough; if it is, calculate thetangent function using sin/cos. If cos(angle) is too small (i.e.the 'else' part), then return an error message. Then, to use this function, you would just write somethinglike: x = mytan(t); Which would store the value of tan(t) in the variable x.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.