2. General Physics

Legal Notice, Disclaimer, and Book Ordering Information:

Null

Setup

\($DefaultFont = {"Courier", 12}; 
Off[General::spell]; 

    Off[General::spell1]; 
PageWidth -> 70; \)

Needs["Graphics`ParametricPlot3D`"]

Needs["Graphics`PlotField`"]

Needs["Graphics`PlotField3D`"]

Clear["Global'*"];

2.4 Problems

2.4.3  Electricity and Magnetism

Problem 2:  Uniformly Charged Sphere

eq1 = {4 π (r^2) Eoutside == totalCharge, 
        4 π (r^2) Einside == enclosedCharge};

totalCharge = (4/3) π (R^3) density; enclosedCharge = (4/3) π (r^3) density;

sol = 
      Solve[eq1, {Einside, Eoutside}][[1
        ]]

efield[rr_, RR_] := 
      (Eoutside /. sol /. {r -> rr, R -> RR}) /; rr > RR; 
    efield[rr_, RR_] := 
      (Einside /. sol /. {r -> rr, R -> RR}) /; 
        rr ≤ RR;

\(\(p1 = 
      Plot[efield[r, 1] /. density -> 1, {r, 1\/10\^6, 3}
	, 
        DisplayFunction -> Identity]; \)\)

medium1 = {GrayLevel[ .7], 
        Polygon[{{1,  .51}, {1, 0}, {3, 0}, {3,  .51}}]}; medium2 = {GrayLevel[ .5], 
        Polygon[{{0,  .51}, {0, 0}, {1, 0}, {1,  .51}}]};

\(\(Show[{Graphics[{medium1, medium2}], 
        Graphics[{Text["Inside ", { .5,  .3}], 
            Text["Outside", {2,  .3}]}], p1}
	, 
      AxesLabel -> {"Distance ", "Electric Field"}
	, 
      Axes -> True
	, DisplayFunction -> $DisplayFunction]; \)\)

potoutside[r_, R_] = 
      (Limit[#1, rMax -> ∞]&)[
        -(∫_rMax^r)(Eoutside /. sol) \[DifferentialD]r]

potinside[r_, R_] = 
      Simplify[potoutside[R, R] - 
          (∫_R^r)(Einside /. sol) \[DifferentialD]r]

potential[r_, R_] := If[r > R, potoutside[r, R], potinside[r, R]];

\(\(p2 = 
      Plot[potential[r, 1] /. density -> 1, {r, 1\/10\^6, 3}
	, 
        DisplayFunction -> Identity]; \)\)

\(\(Show[{Graphics[{medium1, medium2}], 
        Graphics[{Text["Inside ", { .5,  .3}], 
            Text["Outside", {2,  .3}]}], p2}
	, 
      AxesLabel -> {"Distance ", "Potential Field"}
	, 
      Axes -> True
	, DisplayFunction -> $DisplayFunction]; \)\)

Clear[pot]; pot[x_, y_, z_:  0, R_:  1, density_:  1] := 
      If[(x^2) + (y^2) + (z^2) < (R^2), 
        (1/6) density (-((x^2) + (y^2) + (z^2)) + 3 (R^2)), 
        ((density (R^3))/(3 (Sqrt[(x^2) + (y^2) + (z^2)])))]

\(\(potPlot = 
      ContourPlot[pot[x, y], {x, \(-2\), 2}, {y, \(-2\), 2}, 
        ContourShading -> False, ContourSmoothing -> True
	, 
        DisplayFunction -> Identity]; \)\)

\(\(ePlot = 
      PlotGradientField[\(-pot[x, y]\), {x, \(-2\), 2}, {y, \(-2\), 2}
	, 
        ColorFunction -> Hue
	, DisplayFunction -> Identity]; \)\)

\(\(Show[potPlot, ePlot
	, DisplayFunction -> $DisplayFunction]; \)\)

\(\(ePlot3D = 
      PlotGradientField3D[\(-pot[x, y, z]\), {x, 0, 2}, {y, 0, 2}, {z, 0, 2}, 
        VectorHeads -> True
	, ColorFunction -> Hue
	, 
        DisplayFunction -> Identity]; \)\)

point[r_, R_:  1] := {r Sin[theta] Cos[phi], r Sin[theta] Sin[phi], 
        r Cos[theta]}

\(potPlot3D[r_] := 
      ParametricPlot3D[
        Evaluate[point[r]], {theta, 0, π\/2}, {phi, 0, π\/2}, 
        PlotPoints -> 12
	, DisplayFunction -> Identity]\)

\(\(Show[ePlot3D, Table[potPlot3D[r], {r, 1\/2, 2, 1\/2}], 
      PlotRange -> {0, 1}
	, DisplayFunction -> $DisplayFunction]; 
    \)\)