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

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

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