Q:

Write a script that will:

0
  •  Call a function to prompt the user for an angle in degrees
  •  Call a function to calculate and return the angle in radians . (Note: π

radians = 180ْ ) 

  •  Call a function to print the result

Write all of the functions, also. Note that the solution to this problem 

involves four M-files: one which acts as a main program (the script), 

and three for the functions.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ch6Ex13.m

% Script calls functions to:

% prompt for an angle in degrees

% convert to radians

% print both

deg = promptAng;

rad = degRad(deg);

prtDegRad(deg,rad)

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

degRad.m

function rad = degRad(deg)

% Converts an angle from degrees to radians

% Format of call degRad(degrees)

% Returns the angle in radians

rad = deg * pi / 180;

end

prtDegRad.m

function prtDegRad(deg, rad)

% Prints an angle in degrees and radians

% Format of call: prtDegRad(degrees, radians)

% Does not return any values

fprintf('The angle %.1f degrees is \n', deg)

fprintf('equivalent to %.1f radians\n', rad)

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now