NAME: 1. (20) Write a MATLAB function to convert from rectangular (x, y) to pola
ID: 2266299 • Letter: N
Question
NAME: 1. (20) Write a MATLAB function to convert from rectangular (x, y) to polar coordinates (r, 0). The , y coordinates should be the input arguments of the function. You must use the inverse tangent function atan ) in MATLAB within your function to calculate the angle in radians. Since the inverse tangent function returns only angles from-/2 to /2, your code should check for the correct quadrant in the set of coordinate axes to calculate the angle (ie, it should add or substract multiples of /2 to get the angle in the right quadrant) The basic transformation is as follows: = tan-1 ± multiple of /2Explanation / Answer
Matlab Script:
function [r theta] = r2puser(x,y)
r = sqrt((x^2)+(y^2));
if x<0 && y>0 || x<0 && y<0 %2nd quadrant or 3rd quadrant
theta = atan(y/x)+2*pi/2;
else
theta = atan(y/x);
end
test script:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.