Create a user written function that converts degrees to radi

Create a user written function that converts degrees to radians. rightarrow radians = degrees (pi/180) Create a script that: Asks user to input an angle in degrees. If the angle is greaterthan 0: Convert angle to radians (use your user written function from above) Display degrees & radians in a sentence using fprintf (show3 places after the decimal point). If the angle isn\'t greater then 0: Display an error message stating the # input is invalid.

Solution

% matlab code

function radians = degreeToRadians(degrees)
    radians = degrees*(pi/180);
end

degrees = input(\"Enter an angle in degrees: \");
if(degrees > 0)
    radians = degreeToRadians(degrees);
    fprintf(\"Degree: %0.3f\\tRadian: %0.3f\ \",degrees,radians);
else
    disp(\"Invalid angle!\");
end

%{
output:

Enter an angle in degrees: 180
Degree: 180.000 Radian: 3.142

Enter an angle in degrees: -10
Invalid angle!
%}

 Create a user written function that converts degrees to radians. rightarrow radians = degrees (pi/180) Create a script that: Asks user to input an angle in deg

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site