plotting a vector field in polar coordinates

I have a Field given by 3 components. < rho theta z> in cylindrical
E = p*cos(theta),P*sin(theta),z^2 I wish to plot this vector field.
How do i do this. Quiver seems to only work for rectangular. I have also seen people try to convert the field to rectangular which has not worked either. I am at a complete and total loss

Answers (2)

The quiver3 function can do 3D quiver plots. You have to have derivatives of your components as well, but you can calculate them easily enough once you know how you want to take the derivatives. Are ‘p’ and ‘P’ different or a typo? Are they constants or variables as well, and if so, what are they functions of?
An example of your code or an illustration of what plot result you want would help.

5 Comments

sorry the p and P were a typo they were suppose represent rho RHO
The coordinate system is cylindrical (RHO,Theta,Z)
I want to plot the vector field that has the equation
E = p*cos(theta) + P*sin(theta) + z^2
For clarity i have excluded the unit vectors that would normally be attached. example p*cos(theta) is in the RHO direction P*sin(theta) is in the theta direction z^2 is in the Z direction
(RHO,Theta,Z) aka cylindrical
I want to know how to plot this vector field. I hope that clarified this. Im very new to matlab but i have done this before with quiver in 2D
As an example of how i got it to work previously i used the following code
[a b] = meshgrid (0:.2:2*pi , 0:.2:2*pi)
quiver (a,b,sin(a),-sin(b))
That was in 2D and it worked just fine. It gave me a vector field. Now i want to do it in 3D and in cylindrical no rectangular
Would experimenting with the cylinder function work? I’ve used it to to other things, but I never tried to plot on it.
Also, vector fields for the quiver plots require the origin and the derivatives. What of your ‘rho, RHO, theta, z’ are functions (perhaps of time)? If none are, the derivative calculation becomes easier.
If you are correct in saying that quiver requires an independent variable t how did my above 2d example work? Im totally confused
E D I T Did you consider the compass plot? It may do what you want.
————————————————————————————————————————————
Previous Comment: Your 2D example worked because ‘a’ and ‘b’ were the origin points and the sin functions acted as the directional derivatives at those points (at least as far as quiver was concerned).
I didn’t say that quiver or its friends required an independent variable ‘t’ or anything else. I was implying that if your variables were functions of ‘t’ (parametric functions), the directional derivatives would have to be with respect to ‘t’, or whatever the variable was.
Regardless, the first three arguments to quiver3 are the origins of the arrows and the last three arguments are the directions the arrows go. How you choose to define them is entirely up to you. I still have absolutely no idea how you want to define the directional derivatives with respect to your ‘E’ variable, so I can’t help you with that. I also don’t know if ‘E’ are your directional derivatives, the origins of the arrows, or something else. (An easy way to get the last three arguments for quiver3 if you have vectors for the first three, is to use the gradient function.)
I’m just guessing at what you’re doing. You have to provide the details. If you code your cylindrical coordinate system and plot it with quiver3, I will have some idea. If it doesn’t work, I can probably help you get it to work. No promises.
Code would quite definitely help me understand what you’re doing.
@Robert None of your variables are a function of time if your field is static

Sign in to comment.

Robert, you could try to use the following code (hope it works, havn't checked it).
Use the regular quiver to plot the output of the function. For more info Wikipedia page
function [x,y,u_x,u_y]=Fieldpol2cart(r,O,u_r,u_O)
[x,y] = cart2pol(O,r);
u_x = u_r.*cos(O) - u_O.*sin(O);
u_y = u_r.*sin(O) + u_O.*cos(O);

Categories

Asked:

on 14 Feb 2015

Commented:

on 6 May 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!