IN MATLAB he location of a point P in a Cartesian plane can be expressed in eith
ID: 3881298 • Letter: I
Question
IN MATLAB
he location of a point P in a Cartesian plane can be expressed in either the rectangular coordinates (x,y) or the polar coordinates (r,0), as shown in the figure below. The relationships among these two sets of coordinates are given by the following equation: y=: r sin e-tan1 Write two functions rectTOpolar and polarTOrect that convert coordinates from rectangular to polar form, and vice versa, where the angle &is; expressed in degrees. Note that MATLAB's (and also C's) trigonometric functions work in radians, so we must convert from degrees to radians and vice versa when solving this problem. The relationship between degrees and radians is: 180 degrees = radiansExplanation / Answer
Matlab function 1:
function polarTOrect(r,theta)
x=r*cosd(theta) %cosd works with degrees. No need to convert to radians
y=r*sind(theta) %sind works with degrees. No need to convert to radians
end
%function calling polarTOrect
polarTOrect(1,90)
Output: x = 0
y = 1
Matlab function 2:
function rectTOpolar(x,y)
r = sqrt(x^2+y^2)
theta = atand(y/x) %Inverse tangent in degrees
end
%function calling rectTOpolar
rectTOpolar(0,1)
Output: r = 1
theta = 90