New Reply

How to plot 3D vector field in spherical coordinates with Mathematica

 
Share Thread Thread Tools
May25-11, 08:26 AM   #1
 

How to plot 3D vector field in spherical coordinates with Mathematica


I want to graph this vector field -^r/r^2

but I don't know how to do.

Any help would be appreciated.
 
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Heat-related deaths in Manhattan projected to rise
>> Dire outlook despite global warming 'pause': study
>> Sea level influenced tropical climate during the last ice age
May25-11, 04:50 PM   #2
 
Could you enter your vector field in Latexform (tex) (/tex) (replace the "(" and ")" by square brackets? I can't interpret your equation at the moment, i can only guess, what you mean:
[tex]-\frac{1^r}{r^2} \cdot \vec{e_r}[/tex]
or maybe:
[tex]-\frac{r}{r^2} \cdot \vec{e_r} = -\frac{1}{r} \cdot \vec{e_r}[/tex]?

[tex]\vec{e_r}[/tex] is the unit vector in radial direction. Addtionally if you could give more information, if there is any, about your physical problem this would help!

You can test your equation here (without the need of the (tex)(\tex):
http://www.physicsforums.com/mathjax/test/preview.html
Latex information for PhysicsForum:
http://www.physicsforums.com/showthread.php?t=386951
 
May26-11, 10:19 AM   #3
 
What I meant is this [tex]\frac{\hat{r}}{r^2} [/tex].

Regards
Ren-Bo
 
May28-11, 05:14 PM   #4
 

How to plot 3D vector field in spherical coordinates with Mathematica


Ok i assume: [tex]\hat{r}=\vec{e_r}[/tex] is the unit vector in radial direction.

So the following vector field should be evaluated ( i added a minus sign, just remove it for your case):
[tex]\vec{V}=-\frac{1}{r^2} \cdot \vec{e_r}[/tex]

2D Polar Case
What i did to begin with, was reduce your problem to the polar case. The conversion formulas from polar to cartesian coordinate system are (http://en.wikipedia.org/wiki/Polar_coordinate_system):
[tex]r=\sqrt{x^2+y^2}[/tex]
[tex]\varphi=\arctan(\frac{y}{x})[/tex]
and the radial unit vector replaced by cartesian unit vectors is:
[tex]\vec{e_r}=\vec{e_x} \cos(\varphi)+\vec{e_y} \sin(\varphi)[/tex]
All those equations put into your vector field, result in the vector field now being expressed by cartesian coordinates, which you can plot with the following code:
Code:
(* Mathematica Code *)
r[x_, y_] := Sqrt[x^2 + y^2]
\[CurlyPhi][x_, y_] := ArcTan[x, y]
ex[x_, y_] := Cos[\[CurlyPhi][x, y, z]]
ey[x_, y_] := Sin[\[CurlyPhi][x, y, z]]
Vx[x_, y_] := -(1/r[x, y]^2) ex[x, y]
Vy[x_, y_] := -(1/r[x, y]^2) ey[x, y]

VectorPlot[{Vx[x, y], Vy[x, y]}, {x, -1, 1}, {y, -1, 1},
 VectorPoints -> 9,
 RegionFunction -> Function[{x, y, z}, 0.001 < x^2 + y^2 < 2] (*To not evaluate the pole at 0,0 *)
 ]
which results in the plot in attachment 1.
Sidenote: can someone tell me why certain values of the VectorPoints do not display any vectors at all ? Bug or Feature? :)

3D Spherical Case
In a similar way your initial problem is solved. For the conversion from spherical to cartesian see: http://en.wikipedia.org/wiki/Spheric...rdinate_system
The radial unit vector expressed by cartesian unit vectors is this time more complex:
[tex]\vec{e_r}=\vec{e_x} \sin(\theta) \cos(\varphi)+ \vec{e_y} \sin{\theta} \sin(\varphi) + \vec{e_z} \cos(\theta) [/tex]
Code:
r[x_, y_, z_] := Sqrt[x^2 + y^2 + z^2]
\[CurlyPhi][x_, y_] := ArcTan[x, y]
\[Theta][x_, y_, z_] := ArcCos[z/Sqrt[x^2 + y^2 + z^2]]
(* Unit vectors *)
ex[x_, y_, z_] := Sin[\[Theta][x, y, z]] Cos[\[CurlyPhi][x, y, z]]
ey[x_, y_, z_] := Sin[\[Theta][x, y, z]] Sin[\[CurlyPhi][x, y, z]]
ez[x_, y_, z_] := Cos[\[Theta][x, y, z]]
(* Components of the Vector Field *)
Vx[x_, y_, z_] := -(1/r[x, y, z]^2) ex[x, y, z]
Vy[x_, y_, z_] := -(1/r[x, y, z]^2) ey[x, y, z]
Vz[x_, y_, z_] := -(1/r[x, y, z]^2) ez[x, y, z]

VectorPlot3D[{Vx[x, y, z], Vy[x, y, z], Vz[x, y, z]}, {x, -1, 
  1}, {y, -1, 1}, {z, -1, 1},
 VectorPoints -> 5,
 VectorStyle -> "Arrow3D", VectorColorFunction -> Hue,
 AxesLabel -> {"x", "y", "z"}]
For the result see attachment 2.

I would appreciate if someone would crosscheck my results. Since im not that sure about my 3D case when i look onto the attached picture it seems for the line given by x=0,y=0,z there are no "red vectors" for example which point into the center.

@rbwang1225: Please tell me if that helped, and drop in your solution or mathematica code and or picture here when your finished please!
Attached Thumbnails
PolarPlot.png   3DPlot.png  
 
May28-11, 11:14 PM   #5
 
Which version of Mathematica do you use? I failed to use your code in M7 & M8. I don't know why since I think the code is right.

Regards
 
May29-11, 06:03 AM   #6
 
Sorry i broke the code by "cleaning it up", which means i did leave the z-dependence in some equations for [tex]\varphi[/tex] and in the end breaking the code :), here you go, should work with M7.

2D-Case
Code:
(* Mathematica Code *)
r[x_, y_] := Sqrt[x^2 + y^2]
\[CurlyPhi][x_, y_] := ArcTan[x, y]
ex[x_, y_] := Cos[\[CurlyPhi][x, y]]
ey[x_, y_] := Sin[\[CurlyPhi][x, y]]
Vx[x_, y_] := -(1/r[x, y]^2) ex[x, y]
Vy[x_, y_] := -(1/r[x, y]^2) ey[x, y]

VectorPlot[{Vx[x, y], Vy[x, y]}, {x, -1, 1}, {y, -1, 1},
 VectorPoints -> 9,
 RegionFunction -> Function[{x, y}, 0.001 < x^2 + y^2 < 2] (*To not evaluate the pole at 0,0 *)
 ]
3D Spherical Case
Code:
r[x_, y_, z_] := Sqrt[x^2 + y^2 + z^2]
\[CurlyPhi][x_, y_] := ArcTan[x, y]
\[Theta][x_, y_, z_] := ArcCos[z/Sqrt[x^2 + y^2 + z^2]]
(* Unit vectors *)
ex[x_, y_, z_] := Sin[\[Theta][x, y, z]] Cos[\[CurlyPhi][x, y]]
ey[x_, y_, z_] := Sin[\[Theta][x, y, z]] Sin[\[CurlyPhi][x, y]]
ez[x_, y_, z_] := Cos[\[Theta][x, y, z]]
(* Components of the Vector Field *)
Vx[x_, y_, z_] := -(1/r[x, y, z]^2) ex[x, y, z]
Vy[x_, y_, z_] := -(1/r[x, y, z]^2) ey[x, y, z]
Vz[x_, y_, z_] := -(1/r[x, y, z]^2) ez[x, y, z]

VectorPlot3D[{Vx[x, y, z], Vy[x, y, z], Vz[x, y, z]}, {x, -1, 
  1}, {y, -1, 1}, {z, -1, 1},
 VectorPoints -> 5,
 VectorStyle -> "Arrow3D", VectorColorFunction -> Hue,
 AxesLabel -> {"x", "y", "z"}]
If you discover why the red arrows arent plottet for (x=0,y=0,z) please let me know. (or if they work correctly in M8)
 
Jun15-11, 04:11 AM   #7
 
The following is what I got in M8

Click image for larger version

Name:	Untitled-2.jpeg
Views:	43
Size:	21.8 KB
ID:	36477

Thank you!
 
New Reply
Thread Tools


Similar Threads for: How to plot 3D vector field in spherical coordinates with Mathematica
Thread Forum Replies
How do you plot a 3D vector in Mathematica 8? Math & Science Software 1
Position vector in spherical coordinates. Introductory Physics Homework 4
Vector Spherical harmonics/spherical coordinates question General Physics 0
Spherical Coordinates and Mathematica Calculus 2
Vector in spherical coordinates Calculus 0