Create a user defined function that will convert a coordinate (x,y) in the Carte
ID: 3825781 • Letter: C
Question
Create a user defined function that will convert a coordinate (x,y) in the Cartesian Coordinate System to a Polar coordinate (r, theta) where theta is in degrees, referenced positive counter clockwise from the x-axis. Use the function definition line function [r, th] = cart2polar(x,y) in your solution. Keep in mind that there are four quadrants in the Cartesian system and the traditional sine and cosine functions only provide the first quadrant value. Assume only scalar values will be sent to the function.
Explanation / Answer
function [r, th] = cart2polar(x,y)
r=sqrt(x^2+y^2);
th=atand(y/x);
if y<0&&x<0
th=th+180;
elseif y>0&&x<0
th=th+180;
elseif y<0&&x>0
th=360+th;
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.