1
$\begingroup$

I am new to Mathematica and I am trying to create the electric field $F$ from the electric potential $V$ (using arbitrary distances) and then plot the subsequent vector graph to show that the electric field is always pointing away from the point source.

So far I have:

Clear["Global`*"]

(* Creating the Vector Potential V using the Blank operator *)

V[p_, r_] = q/Times[4*Pi*ϵ*Norm[r - p]];
V[{Subscript[x, 1], Subscript[y, 1], Subscript[z, 1]}, {x, y, z}] // 
  TraditionalForm;

(* Creating the Electric Field F using the derivative of the Vector \
Field V *)

F[{x1_, y1_, z1_}] = -D[V[{x1, y1, z1}, {x, y, z}], {{x, y, z}}] /. 
    Derivative[1][Abs][x_] :> x/Sqrt[x^2] // TraditionalForm;

(* Setting the charge q and the constant ϵ *)

q = 1; ϵ = 1;

(* Creating the VectorPlot3D *)

v = VectorPlot3D[F[{1, 1, 1}], {x, -6, 6}, {y, 0, 4}, {z, -4, 4}, 
  VectorStyle -> "Arrow3D", VectorPoints -> 5, 
  VectorScale -> {0.3, Scaled[0.3]}]

But when I run this I don't get any graph.

I've even found an example on Mathematica that doesn't work when I try to run it. Any help would be appreciated!

$\endgroup$
  • 2
    $\begingroup$ Just remove // TraditionalForm from the definition of F. (TradtionalForm is meant for output only, not for something that will be used later in a computation.) $\endgroup$ – jjc385 Sep 18 '17 at 13:04
  • $\begingroup$ @rhermans I know how the site works. I just don't ask questions very often, so no need to log in. $\endgroup$ – Cassidy Hazel Sep 18 '17 at 14:06
2
$\begingroup$

Solution:

Do not mix functions that are meant for display with your mathematical definitions.

Explanation

One must leave TraditionalForm, Subscript TableForm and other forms of Formatted Output for display only and avoid them for programming mathematical definitions.

The TraditionalForm Reference Information documentation explains:

TraditionalForm differs from StandardForm, the default format for input and output. It is important to understand that TraditionalForm expressions cannot always be provided as unambiguous input to the Wolfram System. Therefore, while StandardForm is an input format and an output format, TraditionalForm is primarily intended as an output format.

Furthermore, one should also avoid using Subscript while defining symbols (variables). Subscript[x, 1] is not a symbol, but a composite expression where Subscript is an operator without built-in meaning. For instance, one could expect to do $x_1=2$, but you are actually doing Set[Subscript[x, 1], 2] which is to assign a Downvalue to the oprator Subscript and not an Ownvalue to an indexed x as you may intend. Read how to properly define indexed variables here

Your code for programming the maths

V[p_, r_] = q/Times[4 π ϵ Norm[r - p]];
F[{x1_, y1_, z1_}] = -D[V[{x1, y1, z1}, {x, y, z}], {{x, y, z}}] /. Derivative[1][Abs][x_] :> x/Sqrt[x^2];

With[{q = 1, ϵ = 1},
 v = VectorPlot3D[
   F[{1, 1, 1}]
   , {x, -6, 6}
   , {y, 0, 4}
   , {z, -4, 4}
   , VectorStyle -> "Arrow3D"
   , VectorPoints -> 5
   , VectorScale -> {0.3, Scaled[0.3]}
   ]
 ]

Mathematica graphics

Your code for display only

TraditionalForm[
 V[{Subscript[x, 1], Subscript[y, 1], Subscript[z, 1]}, {x, y, z}]]

enter image description here

TraditionalForm[
 F[{Subscript[x, 1], Subscript[y, 1], Subscript[z, 1]}]]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Thank you, this is perfect! $\endgroup$ – Cassidy Hazel Sep 18 '17 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.