In the diagram below a point at polar coordinates r theta in

In the diagram below, a point at polar coordinates (r, theta) in the polar coordinate system can also be expressed in rectangular coordinates, (a, b) where a = r cos theta and b = r sin theta. Angle theta is in degrees. In MATLAB, the built-in functions for sine, cosine, and tangent are sin, cos, and tan, respectively. The degree versions are available by putting a d at the end of each trig function name (e.g., sind). Write a complete MATLAB function that accepts as input arguments the values of r and theta, performs the conversion, and returns the equivalent coordinates (a, b) as output arguments. Include an appropriate HI line. The function should not prompt the user for input or print any output. The function should work if r and theta, are vectors as well as scalars. Write a script that prompts the user for the r and theta coordinates of a point, calls the function you created above and then displays the returned coordinates. Use fprintf to display the results.

Solution

a) Matlab function is as follows:

  function Frec = polar2rect(Fpol)
Frec = Fpol(:,1).*(cosd(Fpol(:,2))+j*sind(Fpol(:,2)));

b) Type the following command for r = 5 and theta = 36.8699 degrees in the command window and observe the answer:

  >> polar2rect([5 36.8699])

ans =

4.0000 + 3.0000i

The above function works for vectors also.

  

 In the diagram below, a point at polar coordinates (r, theta) in the polar coordinate system can also be expressed in rectangular coordinates, (a, b) where a =

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site