Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Matlab script that asks the user for two angles in degrees and stores th

ID: 3732964 • Letter: W

Question

Write a Matlab script that asks the user for two angles in degrees and stores them as variables. Calculate and store the cosines of the numbers (they must be converted to radians to use Matlab's cos function). Use a conditional statement and fprintf to print the larger of the two cosine values and the angle (in degrees) that resulted in that value. If they are equal, print a message to the effect that the cosines of the two angles (print them) are equal and print the value.

Please fix this code:

prompt = "What is the first angle? ";

angle1_degree = input('give vaue for angle');

prompt = "What is the second angle? ";

angle2_degree = input(prompt);

angle1_radian = deg2rad(angle1_degree);

angle2_radian = deg2rad(angle2_degree);

cos1 = cos(angle1_radian);

cos2 = cos(angle2_radian);

if (cos1 > cos2)

fprintf(" The larger of two cosine values is: %.3f, and the resulting angle is %.2f degress. ", cos1, angle1_degree);

elseif (cos1 < cos2)

fprintf(" The larger of two cosine values is: %.3f, and the resulting angle is %.2 degress. ", cos2, angle2_degree);

else

fprintf(" The cosine of two angles are equal: %.3f ", cos1)

end

Explanation / Answer

% Code

prompt = "What is the first angle? ";

angle1_degree = input(prompt);

prompt = "What is the second angle? ";

angle2_degree = input(prompt);

angle1_radian = deg2rad(angle1_degree);

angle2_radian = deg2rad(angle2_degree);

cos1 = cos(angle1_radian);

cos2 = cos(angle2_radian);

if (cos1 > cos2)

fprintf(' The larger of two cosine values is: %.3f, and the resulting angle is %.2f degress. ', cos1, angle1_degree);

elseif (cos1 < cos2)

fprintf(' The larger of two cosine values is: %.3f, and the resulting angle is %.2 degress. ', cos2, angle2_degree);

else

fprintf(' The cosine of two angles are equal: %.3f ', cos1)

end

Output

What is the first angle?
25
What is the second angle?
75

The larger of two cosine values is: 0.906, and the resulting angle is 25.00 degress.

Explanation

Use single quote marks in fprintf

% Code

prompt = "What is the first angle? ";

angle1_degree = input(prompt);

prompt = "What is the second angle? ";

angle2_degree = input(prompt);

angle1_radian = deg2rad(angle1_degree);

angle2_radian = deg2rad(angle2_degree);

cos1 = cos(angle1_radian);

cos2 = cos(angle2_radian);

if (cos1 > cos2)

fprintf(' The larger of two cosine values is: %.3f, and the resulting angle is %.2f degress. ', cos1, angle1_degree);

elseif (cos1 < cos2)

fprintf(' The larger of two cosine values is: %.3f, and the resulting angle is %.2 degress. ', cos2, angle2_degree);

else

fprintf(' The cosine of two angles are equal: %.3f ', cos1)

end

Output

What is the first angle?
25
What is the second angle?
75

The larger of two cosine values is: 0.906, and the resulting angle is 25.00 degress.

Explanation

Use single quote marks in fprintf

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote