Matlab polar to rectangular coordinates

In summary: I've tried a couple of things but I'm not sure how to make the columns line up properly.In summary, the function m-file converts polar coordinates to rectangular coordinates. It takes two input vectors and converts the radii and angles of each point in the input vectors to corresponding x and y coordinates in the output vectors.
  • #1
ineedhelpnow
651
0
Prepare a function m-file containing a function that converts polar coordinates in two-dimensional space to rectangular (Cartesian) coordinates. Include a suitable H1 line and some additional comment lines. The input will be 2 vectors, and the output will be 2 vectors. The length of each vector (on input and on output) will equal the number of points whose conversion from polar to rectangular coordinates is required.

The radius of a point will appear as an element in the first input vector, and the angle (in radians) of that point will appear as the corresponding element in the second input vector. The first output vector will contain the horizontal (x) coordinates, and the second output vector will contain the vertical (y) coordinates.

In the first section of your script m-file, generate 2 input vectors that you will use to test your function. Use at least 5 points, with any values you want. (Each input vector should be of length 5 or greater.) Then call your function to do the coordinate conversions. Finally, print a table. Each row in the table will correspond to one point. The first 2 columns (of 4 columns in the table) should contain the original polar coordinates, and the last 2 columns should contain the equivalent rectangular coordinates. Use formatted printing. The decimal points in each column should all lie on one vertical line.

Sorry for the super long question but I am fully lost on how to approach this. I'd really appreciate help on it.
 
Physics news on Phys.org
  • #2
I'm not quite as up on my MATLAB as all that, but the equations to convert from polar to rectangular are as follows. Given the magnitude $r$ and direction $\theta$ (which is the angle the vector makes with the positive $x$ axis), the components are given by
\begin{align*}
x&=r \cos(\theta), \\
y&=r \sin(\theta).
\end{align*}
The rest of this problem, it seems to me, is formatting.
 

FAQ: Matlab polar to rectangular coordinates

What is the purpose of converting polar coordinates to rectangular coordinates in Matlab?

The purpose of converting polar coordinates to rectangular coordinates in Matlab is to simplify complex calculations and graphing in a Cartesian coordinate system. It allows for the representation of complex data in a simpler and more intuitive manner.

How do I convert polar coordinates to rectangular coordinates in Matlab?

To convert polar coordinates to rectangular coordinates in Matlab, you can use the built-in function "pol2cart". This function takes in the polar coordinates (radius and angle) and returns the corresponding rectangular coordinates (x and y).

Can I plot polar coordinates in Matlab?

Yes, you can plot polar coordinates in Matlab using the "polarplot" function. This function takes in the polar coordinates and plots them on a polar coordinate system. You can also customize the plot by adding labels, titles, and adjusting the scale.

How do I convert rectangular coordinates to polar coordinates in Matlab?

To convert rectangular coordinates to polar coordinates in Matlab, you can use the built-in function "cart2pol". This function takes in the rectangular coordinates (x and y) and returns the corresponding polar coordinates (radius and angle).

Can I perform mathematical operations on polar coordinates in Matlab?

Yes, you can perform mathematical operations on polar coordinates in Matlab. You can use the "cart2pol" function to convert the polar coordinates to rectangular coordinates, perform the desired operations, and then convert back to polar coordinates using the "pol2cart" function.

Similar threads

Replies
2
Views
1K
Replies
2
Views
1K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
5
Views
2K
Replies
1
Views
4K
Back
Top