Modify the program in Exercise 13 so that the function to calculate the angle is a subfunction to the function that prints
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:6| Question number:14.6
All Answers
total answers (1)
Ch6Ex14.m
% Script calls functions to:
% prompt for an angle in degrees
% print degrees and radians, calling a
% subfunction to convert to radians
deg = promptAng;
prtDegRadii(deg)
promptAng.m
function deg = promptAng
% Prompts for an angle in degrees
% Format of call: promptAng or promptAng()
% Returns an angle in degrees
deg = input('Enter an angle in degrees: ');
end
prtDegRadii.m
function prtDegRadii(deg)
% Prints an angle in degrees and radians
% Calls a subfunction to convert to radians
% Format of call: prtDegRadii(degrees)
% Does not return any values
rad = degRadii(deg);
fprintf('The angle %.1f degrees is \n', deg)
fprintf('equivalent to %.1f radians\n', rad)
end
function rad = degRadii(deg)
% Converts an angle from degrees to radians
% Format of call degRadii(degrees)
% Returns the angle in radians
rad = deg * pi / 180;
end
need an explanation for this answer? contact us directly to get an explanation for this answer