| 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. |
| 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 *)
]
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"}]
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! |
| 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 *)
]
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"}]
|
| Jun15-11, 04:11 AM | #7 |
|
|
|
| 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 | ||