Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 1 Using 'if', 'elseif' and 'else' statements write a MATLAB script that takes x and y coordinates as inputs from the user and
Task 1 Using 'if', 'elseif' and 'else' statements write a MATLAB script that takes x and y coordinates as inputs from the user and computes the angle with respect to the positive x-axis (counter-clockwise) as well as the corresponding quadrant. 1. Angle in the first quadrant when both x and y are positive. 0 = tan | 2. Angle in second quadrant = 180 - 0 - when x is negative and y is positive. 3. Angle in third quadrant = 180 +0 - when x is negative and y is negative. 4. Angle in fourth quadrant = 360 - 0 - when x is positive and y is negative. Quadrant II 180 (-1,0) Quadrant III 90 (0, -1) Test your code for following coordinates: A. (x,y) = (5, 12) (0,1) 270 r=1 The command window should appear like the following: E.g. Enter x coordinate: -5 Enter y coordinate: -12 Required angle is 247.38 and is in the 3rd quadrant E.g. Enter x coordinate: 0 Enter y coordinate: 12 Required angle is 90 degrees and falls on the positive-y axis Quadrant I (1,0) X 0, 360 Quadrant IV B. (x,y) = (0, 12) C. (x,y) = (-5, -12) D. (x,y) = (0, -12) Caution: Inputs of x=0 and y=0 should return an 'undefined' error. Task 2 The circumference of a circle is given by C = 2r where r is the radius. The circumference of an ellipse can be approximated by E = r [3(a + b) (3a + b)(a + 3b)] where a and b are the minor and major axis lengths. A. Write an m-file which prompts the user to specify whether they would like to calculate the circumference of a circle or an ellipse. If the circle option is chosen, ask the user for a radius. If the ellipse option is chosen, ask the user for the minor and major axis lengths. B. Calculate the circumference of the chosen shape. Use fprintf to write a statement containing the shape chosen, the relevant length(s) and the circumference. C. Ask the user if they would like to repeat the calculation. If yes is chosen, go through steps A and B again. If no is chosen, end the code. Hint: Use a while loop to achieve part C. Your code should look similar to the following: Enter either circle (1) or ellipse (2): 1 Enter the radius length: 1 Circle was chosen with a radius of 1. Circumference = 6.283185e+00 Would you like to repeat the calculation? 1=yes, 0=no: 1
Step by Step Solution
★★★★★
3.52 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1
MATLAB Script task TASK1 sprintf sprintf sprintf promptx Enter the value x x inputpromptx prompty En...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started