Electricity
& Magnetism
Mathematica Documentation
Mathematica Source Code
Page 1
(circloop)
A circular loop of wire of radius R is centered
at the origin in the x-y plane and carries a current I counterclockwise
from the x-axis to the y-axis. Perform an integration using the Biot-Savart
law to determine the magnetic field components (Bx,By,Bz) at a point (0,0,H)
due to half of the loop --- that half of the loop where x is greater than
zero.
Clear["Global`*"]
Solution
Load the VectorAnalysis package.
Needs["Calculus`VectorAnalysis`"]
Vector to point in 3D space.
P = {0,0,H}
Vector to point on wire loop.
s = {R*Cos[theta], R*Sin[theta], 0}
Direction around wire loop.
ds = D[s,theta]
Vector from loop to 3D point
r = P-s
Biot-Savart Law
dB = mu0*i*CrossProduct[ds,r]/(4*Pi* Sqrt[Dot[r,r]]^3)//Simplify
Integrate around half loop to find B.
solsymb = Integrate[dB,{theta,-Pi/2,Pi/2}]
The electric field between 2 concentric spheres is E=Q/(4pi eo r^2).
where Q is the charge on the inner sphere of radius A. Plot the capacitance
of these spheres (let the radius of the smaller sphere be 0.25 m) as a
function of the radius of the outer sphere. In the limit as this radius
goes to infinity this might be called the capacitance of a single sphere.
(This is like being asked to put one hand behind your back and clap.) Can
you do the same limiting calculation for flat plates or for cylinders?
[No, only works for concentric spheres]
Clear["Global`*"]
Solution
Enter in the electric field between the two spheres.
Efield = q/(4*Pi*Eo*r^2)
The capacitance of these two spheres is C = q/dV, where dV is the
change in potential of the two spheres. Find dV by integrating E.
dV = Integrate[Efield, {r,R1,R2}]
where R1 is the inner radius and R2 is the outer radius. Thus C
is:
Cap = q/dV//ExpandAll//Simplify
Plot the capacitance as a function of the radius of the outer sphere.
In order to do this, Eo and R1 must be defined.
Eo := 8.854*10^(-12)
R1 := .25
Plot[Cap,{R2,.2501,5}, PlotLabel -> "Capacitance as a function
of R2", PlotRange -> {0, 1*10^(-9)}]
The electric field inside concentric conducting spheres of radius R1
and R2 (R2>R1) is reduced by a factor of 2 when a particular dielectric
material fills the entire space between R1 and R2. This means that the
potential difference between the spheres is also reduced by a factor of
2, and the capacitance is increased by a factor of 2. (The charge Q on
the spheres is kept the same.) When the dielectric doesn't fill the entire
space between the spheres, the capacitance is increased by less than a
factor of 2.
How thick would a dielectric spherical shell of thickness d, extending
from R1 to R1+d have to be in order to increase the capacitance by a factor
1.5? Would this thickness be the same if it extended from R2-d to R2?
Solution
Before starting this problem, turn off one of Mathematica's warning
functions.
Off[Integrate::gener]
Part A: Determine kappa Determine k by using the relationship that
E = Eo/kappa.
eq1 = E == Eo/kappa
Since the field is reduced by a factor of 2, the following is true:
eq2 = eq1/.E -> Eo/2
Now solve for kappa.
eq3 = Solve[eq2,kappa]
Part B: Determine the dielectric's thickness Electric field between
the spheres:
Efield = q/(4*Pi*Eo*r^2)
The difference in potential, V, can be expressed by the following
expression:
V = Integrate[Efield, {r, R1, R2}]
Normal capacitance is related to voltage by the following formula:
eq4 = C == q/V
When a dielectric is added, the capacitance becomes:
eq5 = Cdie == q/Vdie
where Vdie is the difference in potential between the two conducting
spheres, factoring in the dielectric. Now, in order to find the potential
between the two spheres, divide the potential by kappa for r = R1 to R1
+ d, and then add on the regular potential from r = R1 + d to R2.
Vdie = Integrate[Efield, {r, R1, R1 + d}]/kappa +
Integrate[Efield, {r, R1 + d, R2}]
Now the capacitance with the dielectric is:
eq6 = eq5
Now solve for what thickness of dielectric (d) causes the normal
capacitance to increase by a factor of 1.5. Substitute in the value of
kappa obtained in Part A.
sol = Solve[3/2*eq4[[2]] == eq6[[2]], d]/.{kappa
-> 2}
Perform a sanity check. If R1 was 1 and R2 was 2, than d should
be between 0 and 1.
sol/.{R1 -> 1, R2 -> 2}
Part C
Now find out what the result would be if the dielectric extended from R2
- d to R2. The only thing that would change would be Vdie. The new Vdie
would be:
Vdie = Integrate[Efield, {r,R1,R2-d}] + Integrate[Efield,
{r,R2-d,R2}]/kappa
Now the capacitance with the dielectric is:
eq7 = eq5
Now solve for what thickness of dielectric (d) causes the normal
capacitance to increase by a factor of 1.5. Substitute in the value of
kappa obtained in Part A.
sol2 = Solve[3/2*eq4[[2]] == eq7[[2]], d]/.{kappa
-> 2}
Perform a sanity check. If R1 was 1 and R2 was 2, than d should
be between 0 and 1.
sol2/.{R1 -> 1, R2 -> 2}
The electric potential function for a point charge at the origin is
known to be V(r)=q/4 pi eo r. Plot this just considering two dimensions,
x and y. We want to find V if the charge is not at the origin but at x=.1m
and y=.2m. It is claimed that this can be accomplished just by shifting
the coordinate system. Verify this by plotting V(x,y) with x replaced by
x-.1 and y replaced by y-.2.
Solution
Enter in the electric potential function for a point charge at the
origin.
Vr = q/(4*Pi*Eo*r)
By use of the Pythagoreum therom, r can be expressed in terms of
x and y.
Vxy = Vr/.{r -> Sqrt[x^2 + y^2]}
In order to make a plot, the values of q and Eo must be stated.
q := 1.6 * 10^(-19)
Eo := 8.85 * 10^(-12)
Plot the potential function, considering just two dimensions, x
and y.
Plot3D[Vxy//N, {x,-2,2}, {y,-2,2}, AxesLabel ->
{"x","y","V"}, PlotLabel -> "Voltage
in terms of x & y"]
Now shift the coordinate system so that the point charge is now
at x = .1 and y = .2.
Vxy2 = Vxy/.{x -> x - .1, y -> y - .2}
Plot3D[Vxy2//N, {x,-1,1}, {y,-1,1}, AxesLabel -> {"x","y","V"}, PlotLabel -> "Voltage in terms of x & y"]
The file 'ebfields' (ebfields.ms or ebfields.ma) contains a general
solution of the motion of a particle in constant electric and magnetic
fields. For any (Ex, Ey, Ez), (Bx, By, Bz), one can plot the motion of
a particle of mass M, charge q and velocity (vx, vy, vz). From this general
case, it specializes to the motion of a particle in 'crossed' E and B fields
such that the particle travels in a straight line. The particular choices
are q =1.61 x 10^-19 C , M = 1.67 x 10^-27 kg , Bz = 0.50 T , and vx =
8.4 x10^6 m/s.
a) Before opening one of these files, figure out what values are needed
for (Ex,Ey,Ez) so the particle will travel in a straight line.
b) Now imagine reversing the particle's velocity, and predict what sort
of motion it will undergo. (Straight line, motion in a plane, shape of
motion etc.) Now make the changes and compare the results to your predictions.
Going Further:
c) Predict what will happen in the crossed fields when a particle is released
from rest. Try it out and compare results to your predictions.
d) Given the height H bet_ween the top and bottom limits of the y-motion,
what can you say about the velocity of the particle at the top and bottom
y-limits of the motion? [v=0 at bottom where it is released. At top the
kinetic energy is mvx^2 which is equal to the work done on the particle
by Ey, W = qEy H.]
Solution
Before solving this problem, turn off Mathematica's spelling warnings
and load the vector analysis package.
Off[General::spell]
Off[General::spell1]
Needs["Calculus`VectorAnalysis`"]
Define vectors for the general sloution.
Efield = {Ex,Ey,Ez}
Bfield = {Bx,By,Bz}
v = {vx[t],vy[t],vz[t]}
v0 = {vx0,vy0,vz0}
Define equations.
Biot-Savart Law
F = q*Efield + q*CrossProduct[v,Bfield] == m*D[v,t]
Split up force vector into its three components.
NOTE: F[[1,1]] refers to the first item of the first vector; F[[2,1]] refers
to the first item of the second vector.
Fx = F[[1,1]] == F[[2,1]]
Fy = F[[1,2]] == F[[2,2]]
Fz = F[[1,3]] == F[[2,3]]
Enter in the given initial conditions for the E and B fields as
well as information about the particle.
EV := {0,2/10,0}
BV := {2/10,-2/10,2/10}
VV := {0,-1,0}
charge := (16/10)*10^(-19)
mass := (167/100)*10^(-27)
Now substitute that information into the force equations.
Fxx = Fx/.{Ex -> EV[[1]], By -> BV[[2]], Bz
-> BV[[3]], q -> charge, m -> mass}
Fyy = Fy/.{Ey -> EV[[2]], Bx -> BV[[1]], Bz -> BV[[3]], q ->
charge, m -> mass}
Fzz = Fz/.{Ez -> EV[[3]], By -> BV[[2]], Bx -> BV[[1]], q ->
charge, m -> mass}
Now simultaneously solve the three force equations.
*NOTE: In order to simultaneously solve the force equations, Laplace Transformations
had to be used. DSolve did not work. Load the LaplaceTransform package
and take the laplace of the three force equations.
Needs["Calculus`LaplaceTransform`"]
lpfxx = LaplaceTransform[Fxx,t,s]
lpfyy = LaplaceTransform[Fyy,t,s]
lpfzz = LaplaceTransform[Fzz,t,s]
Now substitute in the initial conditions for the particle's velocity.
lpfxxs = lpfxx/.{vx[0] -> VV[[1]]}
lpfyys = lpfyy/.{vy[0] -> VV[[2]]}
lpfzzs = lpfzz/.{vz[0] -> VV[[3]]}
Now simultaneously solve the three equations for the laplace of
vx[t], vy[t], and vz[t].
sol = Solve[{lpfxxs,lpfyys,lpfzzs}, {LaplaceTransform[vx[t],t,s],LaplaceTransform[vy[t],t,s],
LaplaceTransform[vz[t],t,s]}]
Now take the inverse laplace of vx[t], vy[t], and vz[t]. This will
give you the particle's velocity in component form. vxt
= N[InverseLaplaceTransform[LaplaceTransform[ vx[t],t,s]/.sol[[1,1]],s,t]]//Simplify
vyt = N[InverseLaplaceTransform[LaplaceTransform[ vy[t],t,s]/.sol[[1,2]],s,t]]//Simplify
vzt = N[InverseLaplaceTransform[LaplaceTransform[ vz[t],t,s]/.sol[[1,3]],s,t]]//Simplify
Integrate the xyz velocity components to find the position. Also
write the position components in vector form.
positionxyz = {Integrate[vxt,t],Integrate[vyt,t],
Integrate[vzt,t]}//Simplify
Locate the particle at t = 0 on the graph.
positionxyz0 = positionxyz/.{t -> 0}
Assign positionxyz0 to be real.
positionxyz0 := {1.15972*10^-8, -(1.15972*10^-8),
-(2.31944*10^-8)}
*******Input Section For Graphical Output*******
Values in this section may be repeatedly changed without executing
the upper cells again. The three scalar variables control how large E,
B, and velocity vectors will be drawn on the graph. If too large a value
is used, the vector will dominate the plot and the path of the particle
will be too small to see. If too small a value is used, the vector will
be too small to tell its direction.
scalarE := 1/5
scalarB := 1/5
scalarV := 1/10
The path of the particle is plotted from t = 0 to the time entered
for tmax. If the output on the graph looks like "star" patterns,
the value of tmax is probably too large. If the output looks like a straight
or nearly straight line, tmax is probably too small. Execute the remaining
cells in this notebook to get the solution.
tmax := 2*10^(-7)
Generates each component for the path of the particle and the field
and velocity vectors.
position = ParametricPlot3D[Evaluate[positionxyz],
{t,0,tmax},BoxRatios -> {1,1,1}];
efield = ParametricPlot3D[Evaluate[(EV*scalarE*t)], {t,0,tmax}, BoxRatios -> {1,1,1}];
bfield = ParametricPlot3D[Evaluate[(BV*scalarB*t)], {t,0,tmax}, BoxRatios -> {1,1,1}];
velocity = ParametricPlot3D[Evaluate[(positionxyz0 + VV*scalarV*t)], {t,0,tmax}, BoxRatios -> {1,1,1}];
Locate the position for the end of each vector. This will allow
labels to be accuratly placed on the final diagram.
Eend = EV*scalarE*tmax
Bend = BV*scalarB*tmax
Vend = positionxyz0 + VV*scalarV*tmax
Displays all four components, with labels, on the same graph.
Show[position,efield,bfield,velocity, Graphics3D[Text["E",{Eend[[1]],Eend[[2]],Eend[[3]]},
{-1,0}]], Graphics3D[Text["B",{Bend[[1]],Bend[[2]],Bend[[3]]},
{-1,0}]], Graphics3D[Text["V",{Vend[[1]],Vend[[2]],Vend[[3]]},
{-1,0}]], PlotLabel -> "Motion of particle through E and B fields",
Axes -> True, AxesLabel -> {"x","y","z"},
Ticks -> {{0},{0},{0}}];
Along the axis of a finite dipole, the electric field points one way in x = -a to +a, and it points the other way outside the charges. Which field produces the greater effect? The one in between is stronger, but it doesn't last very long. To answer this question, we set up a line of dipoles, and integrate along the line of the dipoles, although we do not run right over the top of any individual charge.
Set up a line of 4 dipoles in the y-direction and integrate from x = -a to +a and find out the average electric field. Will it be + or - ?
A line of + charges at (0,1/8), (0,3/8), (0,-1/8), (0,-3/8) and a line of - charges at x = +1/4. This gives 4 dipoles pointing in -x direction, from y = -3/8 to y = +3/8 m. Distance is 1/4 in x and y directions.
Predict the sign of Ex before beginning. [It should be mainly negative outside +/- charges and positive between the charges.] Graph Ex from -2 to 2 and see Ex is negative (mostly) outside dipoles, and large positive between them. Who wins? Integrate Ex from -2 to 2 and see. [Easy way to understand result is that V is positive for x<0 since al + charges are closer, and V is negative for x> 1/4 because all negative charges are closer! ]
STILL UNDER CONSTRUCTION
In AM (amplitude-modulated) radio, the amplitude
of a high-frequency signal is modualted by hte lower-frequency audio information.
AM radios use 'envelope detectors' involving RC circuits in order to remove
the high-frequency (the 'carrier wave') and leave the audio signal.
This problem gives you a simple modulated signal. It also gives you the
'rectified' signal we would see after passing through a diode (which lets
current flow in one direction only).
You are to pass the signal through a series RC circuit, first through a
resistor R and then a capacitor C to ground. The 'envelope' signal is to
be the voltage across the capacitor.
Letting v be the incoming signal, the equation to be solved is V - I*R
- q/C = 0.
You must replace the current I by a function of q, the charge on the capacitor.
This (call it eq1) will be the generic equation to be solved for q, the
charge on the capacitor as a function of time. By substituting values of
R and C into eq1, you get eq2. This new equation is to be solved numerically
for q (the charge on the capacitor) as a function of time.
a) Get the rectified signal first, by using the Heaviside function. The
input signal is
v := Sin[96 Pi t] * Sin[12000 Pi t]
b) Set up the differential equation, using q(t)
for the charge on the capacitor C. C is connected to ground and to the
resistor R. R has the input voltage on one side and C on the other. [The
current will be dq/dt]
c) Substitute values into the DE to make the new DE which will be solved
numerically. Start off by setting RC equal to 1/10, the period of the 'carrier
frequency.'
d) Solve the new DE numerically. Plot and see what the gives you for an
envelope function. Compare this to the plot on the modulated function.
Clear["Global`*"]
Carrier frequency is 2000 Hz
th = 6000*2*Pi*t;
Amplitde-modulated (AM) signal (modulated
at 48 Hz)
z = Sin[th*8/1000]*Sin[th]
Build the Heaviside function.
Heaviside[x_] = If[x>0,1,0]
v = z*Heaviside[z]
Plot[v,{t,0,0.015}, PlotPoints -> 400, PlotLabel -> "Plot of
the Modulated Signal"]
From here on down, the students should be
doing the work.
eq1 = v-R*D[q[t],t] - q[t]/C == 0;
eq2 = eq1/.{R -> 45, C -> 1/100000}
RC is 0.45 ms. carrier pd = 0.17 ms. modulation
pd = 20 ms.
sol = NDSolve[{eq2, q[0] == 0, q'[0] == 0},
q, {t,0,.02}, MaxSteps -> 3000, AccuracyGoal -> 9]
Plot[Evaluate[(q[t])/.sol]*100000/1, {t,0,.012}, PlotPoints -> 300, PlotLabel -> "Signal Across Capacitor"]
Note that we don't get all of the signal back, nor is the shape a perfect fit to the envelope.
R-C circuits are often used as simple frequency filters in electronic
circuits. To see how this works, apply an input voltage of v(t) = A cos
(wt) to a series resistor-capacitor (the input voltage is applied at the
resistor R and the output voltage is taken at the point where the resistor
R and capacitor C join together. One side of the capacitor is connected
to the resistor and other side is grounded.). V is the voltage across the
capacitor, and q is the charge magnitude on either plate, so q = VC, from
the definition of capacitance. The time derivative of this relation is
: dq/dt = current = I = C dV/dt.
a) Show that the loop equation for voltage can be written v(t) = RC dV/dt
+ V
b) Use dsolve to obtain a solution to the second of these equations for
V(t).
c) Assume R= 10 k ohms, C = 0.12 microfarads, A = 0.350 V, and w=6328 rad/s.
Plot the voltage across the capacitor vs. time. If the voltage amplitude
across the capacitor is close to A, then the circuit is 'passing' most
of the input voltage through to the output at this frequency.
d) Plot the ratio of the amplitude of the voltage across the capacitor
to the input voltage amplitude A from frequencies from 10 rad/sec to 2000
rad/sec.
e) Based on this plot, would you say this filter is a 'high-pass' or a
'low-pass' filter?
Solution
Part A
Current through the capacitor at the output
i = C*D[Vout[t],t]
Voltage across resistor
eq1 = Vr[t] == i*R
Write Vr[t] in terms of Vin[t] and Vout[t].
eq2 = eq1/.{Vr[t] -> Vin[t] - Vout[t]}
Substitute the input voltages given in the problem for Vin[t].
DE = eq2/.{Vin[t] -> A*Cos[omega*t]}
Part B
Solve the differential equation for Vout[t] using initial conditions.
sol = DSolve[{DE, Vout[0] == 0}, Vout[t], t]//Flatten
Part C
Substitute in values for the constants.
Voutsub = sol[[1,2]]/.{R -> 10000, C -> .12*10^(-6),
A -> .35, omega -> 6238}
Plot[Voutsub, {t,0,.005}, PlotLabel -> "Voutsub vs. time"]
Part D
Voutsub2 = sol[[1,2]]/.{R -> 10000, C -> 12/100*10^(-6),
A -> 35/100}
Find the steady state response by eliminating the exponential terms.
Vss = Voutsub2/.{Exp[-2500/3*t] -> 0 }//Simplify//ExpandAll
Now calculate the amplitude of Vss.
Aout = Sqrt[Vss[[1,{1,2}]]^2 + Vss[[2,{1,2,3}]]^2]//Simplify
Plot[Aout/.35, {omega,0,2000}, PlotLabel -> "Gain of the circuit vs. omega", PlotRange -> {0,1}]
Part F
The circuit is acting like a low pass filter.
Now solve the problem in the S domain.
Use Vltage division to find Vout.
VoutS = (35/100)/(C*I*omega)/(R+1/(C*I*omega))//Expand
Find the amplitude of the output.
AoutS = ComplexExpand[Abs[VoutS],{I}]
Find the amplitude of the output using the values for R and C given
in the problem.
AoutSsub = AoutS/.{R -> 10000, C -> 12/100*10^(-6)}//Simplify
Note that this answer is the same as the answer given by the differential equation.
Use the basic solution in 'ebfields' to create an particle trajectory
which is a helix. Let q =1.6x10^-19C, and M = 1.67x10^-27 kg , as before.
Change any of (Ex, Ey, Ez), (Bx, By, Bz), or (vx, vy, vz), and create a
radius for the helix of R=2.30 m, and a 'pitch' of 0.250 m for each revolution.
Solution
Before solving this problem, turn off Mathematica's spelling warnings and
load the vector analysis package.
Off[General::spell]
Off[General::spell1]
Needs["Calculus`VectorAnalysis`"]
Define vectors for the general sloution.
Efield = {Ex,Ey,Ez}
Bfield = {Bx,By,Bz}
v = {vx[t],vy[t],vz[t]}
v0 = {vx0,vy0,vz0}
Define equations.
Biot-Savart Law
F = q*Efield + q*CrossProduct[v,Bfield] == m*D[v,t]
Split up force vector into its three components.
NOTE: F[[1,1]] refers to the first item of the first vector; F[[2,1]] refers
to the first item of the second vector.
Fx = F[[1,1]] == F[[2,1]]
Fy = F[[1,2]] == F[[2,2]]
Fz = F[[1,3]] == F[[2,3]]
******* INPUT SECTION FOR PROBLEM ******
Calculate values needed to produce the helix stated in the problem.
First, find the component of the velocity vector perpendicular to the B
field needed to make the particle travel in a 2.3 m circle.
The radius of a particle's orbit in a magnetic field is:
orbit = r == m*V/(q*B)
Substitute in values for m, q, B, and r. B must be made small enough
so that V is not relativistic.
orbitsub = orbit/.{r -> 2.3, m -> 1.67*10^(-27),
q -> 1.61*10^(-19), B -> 1/1000}
Now solve for V. Suppose B is in the +z direction. V would then
have to lie in the x-y plane.
Vx = Solve[orbitsub, V]//Flatten
Assign the solution.
Vx = Vx[[1,2]]
We want the particle to travel in a helix path, so a velocity component
in the z direction is also needed.
We know Vx and r, so the time for one orbit of the particle is:
Time = 2*Pi*r/Vx/.{r -> 2.3}//N
In order for the helix to have the pitch specified in the problem,
it must travel 0.250 m during each revolution.
Vz = .25/Time
Now enter in the given initial conditions for the E and B fields
as well as information about the particle.
EV := {0,0,0}
BV := {0,0,1/1000}
VV := {Vx,0,Vz}
charge := (161/100)*10^(-19)
mass := (167/100)*10^(-27)
Now substitute that information into the force equations.
Fxx = Fx/.{Ex -> EV[[1]], By -> BV[[2]], Bz
-> BV[[3]], q -> charge, m -> mass}
Fyy = Fy/.{Ey -> EV[[2]], Bx -> BV[[1]], Bz -> BV[[3]], q ->
charge, m -> mass}
Fzz = Fz/.{Ez -> EV[[3]], By -> BV[[2]], Bx -> BV[[1]], q ->
charge, m -> mass}
Now simultaneously solve the three force equations.
*NOTE: In order to simultaneously solve the force equations, Laplace Transformations
had to be used. DSolve did not work. Load the LaplaceTransform package
and take the laplace of the three force equations.
Needs["Calculus`LaplaceTransform`"]
lpfxx = LaplaceTransform[Fxx,t,s]
lpfyy = LaplaceTransform[Fyy,t,s]
lpfzz = LaplaceTransform[Fzz,t,s]
Now substitute in the initial conditions for the particle's velocity.
lpfxxs = lpfxx/.{vx[0] -> VV[[1]]}
lpfyys = lpfyy/.{vy[0] -> VV[[2]]}
lpfzzs = lpfzz/.{vz[0] -> VV[[3]]}
Now simultaneously solve the three equations for the laplace of
vx[t], vy[t], and vz[t].
sol = Solve[{lpfxxs,lpfyys,lpfzzs}, {LaplaceTransform[vx[t],t,s],LaplaceTransform[vy[t],t,s],
LaplaceTransform[vz[t],t,s]}]
Now take the inverse laplace of vx[t], vy[t], and vz[t]. This will
give you the particle's velocity in component form.
vxt = N[InverseLaplaceTransform[LaplaceTransform[
vx[t],t,s]/.sol[[1,2]],s,t]]//Simplify
vyt = N[InverseLaplaceTransform[LaplaceTransform[ vy[t],t,s]/.sol[[1,3]],s,t]]//Simplify
vzt = N[InverseLaplaceTransform[LaplaceTransform[ vz[t],t,s]/.sol[[1,1]],s,t]]//Simplify
Integrate the xyz velocity components to find the position. Also
write the position components in vector form.
positionxyz = {Integrate[vxt,t],Integrate[vyt,t],
Integrate[vzt,t]}//Simplify
Locate the particle at t = 0 on the graph.
positionxyz0 = positionxyz/.{t -> 0}
*******Input Section For Graphical Output*******
scalarE := 1
scalarB := 3000000
scalarV := 1/25
Make 4 loops.
tmax := 4*Time
Generates each component for the path of the particle and the field
and velocity vectors.
position = ParametricPlot3D[Evaluate[positionxyz],
{t,0,tmax},BoxRatios -> {1,1,1}];
efield = ParametricPlot3D[Evaluate[(EV*scalarE*t)], {t,0,tmax}, BoxRatios -> {1,1,1}];
bfield = ParametricPlot3D[Evaluate[(BV*scalarB*t)], {t,0,tmax}, BoxRatios -> {1,1,1}];
velocity = ParametricPlot3D[Evaluate[(positionxyz0 + VV*scalarV*t)], {t,0,tmax}, BoxRatios -> {1,1,1}];
Locate the position for the end of each vector. This will allow
labels to be accuratly placed on the final diagram.
Eend = EV*scalarE*tmax
Bend = BV*scalarB*tmax
Vend = positionxyz0 + VV*scalarV*tmax
Displays all four components, with labels, on the same graph.
Show[position,efield,bfield,velocity, Graphics3D[Text["E",{Eend[[1]],Eend[[2]],Eend[[3]]},
{-1,0}]], Graphics3D[Text["B",{Bend[[1]],Bend[[2]],Bend[[3]]},
{-1,0}]], Graphics3D[Text["V",{Vend[[1]],Vend[[2]],Vend[[3]]},
{-1,0}]], PlotLabel -> "Motion of particle through B field",
Axes -> True, AxesLabel -> {"x","y","z"},
Ticks -> {{0},{0},{0}}];
Make a 3D plot of the magnitude of the magnetic field between a pair
of helmholtz coils. (See problem 'loopaxis' for the setup of helmholtz
coils.) [In parts a) and b) below, try to use the contours of the 3D plot
to help you answer the questions.]
a) How far from the center of the coils do we have to go laterally before
the field magnitude changes by 10%. Express your answer in terms of the
coil radius (0.25 radii, 0.32 coil radii, or whatever).
b) How far from the center do we have to go along the axis before the magnitude
of the field changes by 10%?
Solution
Load the necessary package.
Needs["Calculus`VectorAnalysis`"]
Vector to point in 3d space.
P = {x,y,z}
Vector to point on wire loop.
s = {R*Cos[theta], R*Sin[theta], 0}
Direction around wire loop.
ds = D[s,theta]
Vector from loop to 3d point.
r = P - s
Biot-Savart Law
dB = mu0*i*CrossProduct[ds,r]/(4*Pi*Sqrt[Dot[r,r]]^3)
Substitute in the values of the known constants.
dBvectsub = dB/.{R -> 1, mu0 -> 4*Pi*10^(-7),
i -> 1}//Simplify
Evaluate the integrals by using an approximation with rectangles.
";" supresses the output.
Bxyz = (Pi/12)*Sum[dBvectsub, {theta,Pi/24,2*Pi,Pi/12}];
Position a second coil 1m from the first coil.
Bxyz2 = Bxyz/.z -> (z-1);
Add the fields of the two coils together.
Bxyztot = Bxyz + Bxyz2;
Find the magnitude of the combined field.
Bmag = Sqrt[Bxyztot[[1]]^2 + Bxyztot[[2]]^2 + Bxyztot[[3]]^2];
Take a cross section of the B field in the xz plane.
Bmagxz = Bmag/.y -> 0;
Plot the B field in the xz plane.
Plot3D[Bmagxz, {x, -1.5,1.5}, {z,-.5,1.5}, PlotPoints
-> 30, PlotRange -> {0,1.5*10^(-6)}, PlotLabel -> " |B| in
the xz plane"]
Animate the same function as in the 3D plot to "walk"
through the shape above. Notice how little the field in the middle changes.
Do[Plot[Bmagxz/.z -> i,{x,-1.5,1.5}, PlotRange
-> {{-1.5,1.5},{0,2*10^(-6)}}, PlotPoints -> 50 ],{i,0,1,.2}]
Find the field at the center of the two coils.
field`at`center = Bmag/.{z -> .5, x -> 0, y
-> 0}//N
90% of the field
field90 = .9*field`at`center
110% of the field
field110 = 1.1*field`at`center
Plot the area in the xz plane that has a magnetic field within 10%
of the center.
ContourPlot[Bmagxz, {x,-1.5,1.5}, {z,-.5,1.5}, PlotRange
-> {field90,field110}, ContourSmoothing -> Automatic]
Magnitude of field along z axis.
Bmagz = Bmag/.{x -> 0, y -> 0};
Magnitude of field between the two coils.
Bmagx = Bmag/.{y -> 0, z -> 1/2};
Plot[{Bmagx//N,field90,field110}, {x,-1.5,1.5}, PlotRange
-> {0,1.2*10^(-6)}, PlotLabel -> "B along x when z = .5"]
Part A
Find lateral distance for field to change by 10%
Since R = 1, answer is in radii
FindRoot[Bmagx == field90, {x, .65}]
Plot[{Bmagz,field90,field110},{z,-.5,1.5}, PlotRange -> {0,1.2*10^(-6)}, PlotLabel -> "B along z axis"]
Part B
Find the distance along z axis for field to change by 10%
sol = FindRoot[Bmagz == field90, {z,1.1}]
Subtract 1/2 from the answer to measure the distance from the center.
Again, the answer is in radii.
dist = sol[[1,2]] - .5
A rectangular current loop measures 1.50 m by 0.90 m, and carries a
current of 10.5 A. At the mid-point of the long (1.50 m) leg inside the
loop, how far would we have to be from the wire so that the magnetic field
there would be within 2% of the field we would calculate assuming wire
to be infinitely long?
Solution
Formula for magnetic field of a finite length of wire
B = mu0*i*(Cos[theta]+Cos[phi])/(4*Pi*d)
B field for the top horizontal 1.5 m segment
Bth = B/.{d -> y, Cos[theta] -> (3/4)/Sqrt[(3/4)^2+y^2],
Cos[phi] -> (3/4)/Sqrt[(3/4)^2 + y^2]}//Simplify
B field for the lower horizontal 1.5 m segment
Blv = B/.{d -> 3/4, Cos[theta] -> y/Sqrt[y^2
+ (3/4)^2], Cos[phi] -> (9/10 - y)/Sqrt[(9/10 - y)^2 + (3/4)^2] }//Simplify
B field for the right vertical .9 m segment
Brv = Blv
Total B field is then:
Bloop = Bth + Blh + Blv + Brv//Simplify
For a long wire, the magnetic field at a distance y from the wire
is:
Blong = mu0*i/(2*Pi*y)
Find y where the magnetic field from the loop is within 2% of the
magnetic field from a "long" wire at the same distance y.
ratio = Bloop/Blong == 102/100
ans = NSolve[ratio,y]
The answer of importance is the smallest, positive root
answer = ans[[2,1,2]]

A "real"inductor has inductance (L) and resistance (RL). Suppose
this component is connected in parallel with an ideal capacitor (C), as
shown above.
a) Find the magnitude of the effective impedience of the combination as
a function of the frequency.
b) Find the phase relationship between the voltage across the combination
and the current through it.
c) Suppose the combination is connected in series with a pure resistance
(R), as shown. A voltage given by:
Vin = Vo Cos(wt)
is applied to the entire circuit. Find Vout(t), the voltage across the
parallel combination.
d) Let Vo = 5, L = 3 mH, C = 10 uF, RL = 3 ohms, R = 1000 ohms. Plot the
magnitude of the frequency response of the circuit for f = 0 Hz to 2000
Hz.
STILL UNDER CONSTRUCTION
Clear["Global`*"]
Part A
Capacitor impedience
ZC = 1/(I*omega*C)
Inductor impedience
ZL = I*omega*L
Resistor impedience
ZR = RL
Impedience of the combination of elements
Zeff = 1/(1/(ZL+ZR) + 1/ZC)//Simplify
Magnitude of the impedience
magZeff = Sqrt[Zeff^2]
Part B
Convert the complex impedience into polar form.
sol = ComplexExpand[magZeff, {I}, TargetFunctions -> {Abs, Arg}]//Simplify
Evaluate the phase angle of the impedience.
sol[[1]]
An ink drop of radius 0.028 mm (density = 1000 kg/m^3) is travelling
at a speed of 90 m/s. It passes through deflecting plates which are 8 mm
long and separated by 1.5 mm. We assume the print head slews horizontally
across the page. Since the drops must be able to cover the whole field
of a single character in the vertical direction, they must be able to be
deflected at least 0.5 mm up or down. The voltage difference across the
deflecting plates is 2200 V.
a) Find the electric field E between the deflecting plates in V/m.
b) Determine the charge Q which must be on a drop in order to deflect it
by 0.50 mm by the time it has reached the edge of the deflecting plates.
[Sanity-check your answer by noting that the smallest charge which can
be applied is 1.6 x 10^-19C ].
c) The width of the deflecting plate is 6 mm. Determine the total charge
on the deflecting plate in order create the potential difference of 2200
V and the electric field E. [Assume the charge on each deflecting plate
is uniformly distributed over the plate. Note: the total charge on the
plate shoud be much larger than the charge on the drop going through the
plates if the drop is not to change the field.]
Going Further:
d) Estimate the time needed to print a single page with this printer, figuring
that around 100 drops are needed per character. [Ans: Time/drop from vel
and length of deflecting plates is about 10^-4sec, there are about 2400
chars/page, about 20 seconds per page.]
Solution
Part A: The E field
The E field is related to the voltage difference and distance between plates
by the formula:
Efield = V/d
Now substitute in the given values for V and d.
Efield2 = Efield/.{V -> 2200, d -> .0015}
Part B: Particle's Charge
Calculate the particle's mass.
Density equals mass over volume, so mass equals density times volume
m = density*volume
Now substitute in the given values, assuming the inkdrop to be a
sphere.
m = m/.{density -> 1000, volume -> (4/3)*Pi*
(28*10^(-6))^3}//N
Now calculate the particle's acceleration.
The following kinematic formula can be used:
kin = x == xo + vo*t + 1/2*a*t^2
xo and vo are both 0 because the ink drop has no initial motion
in the vertical direction. x is .0005 because that is how far the particle
is to be deflected. t is .008m (the length of the plates) divided by 90m/s
(the speed of the drop through the plates).
Substituting in these values, and solving for a gives:
kin2 = kin/.{xo->0, vo->0, x->.0005, t->.008/90}
acc = Solve[kin2, a]//Flatten
Setting the two force equations (F = q*E and F = m*a) equal to each
other gives:
force = charge*ElectricField == mass*acceleration
Now define the calculated values from parts a, b, and c.
ElectricField = Efield2
acceleration = acc[[1,2]]
mass = m
Now the force equation is:
force
Now solve for the charge of the ink drop.
q = Solve[force, charge]//Flatten
Part C: Total charge on the plate
By using Gauss's Law (E*A = q/e0), the total charge on the plate can be
calculated.
GaussLaw = ElecField*Area == charge/Eo
Now substitute in the know values.
GaussLaw2 = GaussLaw/.{Area -> (.008*.006), ElecField
-> Efield2, Eo -> 8.85*10^(-12)}
Now solve for the total charge.
Solve[GaussLaw2, charge]
Note that the charge on the plate is bigger than the charge on the particle by a factor of 100.
Part D
An inkdrop will travel through the deflecting plates in the following time:
time = .008/90
where .008 is the length of thedeflecting plates and 90 is the speed
of the inkdrop.
Therefore, one character will be produced in the time it takes for 100
drops to go through the deflecting plates one at a time.
char = time*100
Assuming 2400 characters per page, one page will be printed in char*2400
seconds.
OnePage = char*2400
In a region where the elecrtric field is (i 3.4 x10^3 + j 2.13) N/C,
determine the potential difference between the points (1.0,1.5) m and ((0.5,
2.5) m:
a) By taking the dotproduct of the electric field vector and the the vector
from P1 to P2.
b) By integrating along the vector from P1 to P2.
c) By first integrating in the x direction and then in the y direction
Solution
Part A
Enter in the electric field as a vector.
Efield = {3400,2.13}
Enter in the positions of the points as vectors.
P1 = {1,1.5}
P2 = {.5,2.5}
Vector from P1 to P2
s = P2 - P1
Find the magnitude of s.
mags = Sqrt[Dot[s,s]]
Since the electric field is a constant, the potential difference
is simply -E•s
U = -Dot[Efield,s]
Part B
Unit vector in the direction of s.
ds = s/mags
U = -Integrate[Dot[Efield,ds], {ss,0,mags}]
Part C
Define fields in the x and y directions.
Efieldx = Efield[[1]]
Efieldy = Efield[[2]]
Integrate in the x direction from x = 1.0 to 0.5.
Ux = -Integrate[Efieldx, {x,1,.5}]
Integrate in the y direction from y = 1.5 to 2.5.
Uy = -Integrate[Efieldy, {y,1.5,2.5}]
The potential difference between P1 and P2 is the sum of the change
in potentials along the two paths.
U = Ux + Uy
Axial magnetic fields from 1, 2, and several loops of current-carrying
wire.
a) Use the starter material and evaluate the formula at the center of the
loop. b) Make a function f1, where you substitute i = 1 amp and mu = 4
Pi * 10^(-7). Put the coil center at z = 0, give it a radius of 1 m, and
plot f1 from z = 0 to z = 4.
c) At the coil center the slope of Bz is zero and again at z = infinity.
Locate the value of z where the slope magnitude is a maximum. [Hint: what
does this have to do with the second derivative of the function?]
d) Put a second coil at z = 1.2 m and plot Bz for the pair of coils.
e) Evaluate the 1st and 3rd derivatives of the B field halfway between
the two coils.
f) Use a loop to create a 'loose' solenoid of 5 coils. Plot axial magnetic
field (should have some wiggles in it.)
g) Estimate the area under the graph of B along the axis by using a rectangle.
Clear["Global`*"]
f = Bz at (0,0,z) from loop centered at z = c, radius R. This is
our basic building block.
f = mu/(4*Pi)*i*2*Pi*R^2/(R^2 + (z-c)^2)^(3/2)
Check it at center of the loop; want mu I / 2R
f/.{z->0,c->0}//Cancel
f1 = f/.{i -> 1, mu -> 4*Pi*10^(-7)}
Plot this to see what it looks like ( put at z = 2 and plot 0 to
4)
Plot[f1/.{R -> 1, c -> 2}, {z,0,4}]
Two loops seperated by 1.2 units.
loop1 = f1/.{R -> 1, c-> 0};
loop2 = f1/.{R -> 1, c-> 12/10};
twoloops = loop1 + loop2
2nd derivative of f:
d2 = D[f,{z,2}]
Solution gives two answers for where Bz is zero for a single loop,
half a radius away from the loop center to either side.
sol = Solve[d2 == 0 , z]
first derivative:
d1 = D[twoloops,z]
Check it at z = 0.6
d1/.z->6/10
3rd derivative:
d3 = D[twoloops,{z,3}]
Check it at z = 0.6
d3/.{z -> 6/10}
Plot the axial field of 2 loops, one at zero, one at 1.2.
Plot[twoloops, {z,0,1}]
two1 = f1/.{R->1,c->1/4};
two2 = f1/.{R->1,c->3/4};
twoa = two1 + two2
Example of plotting two 'functions' together
Plot[{1*10^(7)*twoloops, 1*10^(7)*twoa}, {z,0,1}]
Example of how to use a software loop to make a group of coils.
g = 0;
Do[g = g+f1/.{R->1/8,c->k/6},{k,1,4}];
g
Plot[1*10^6*g,{z,-1,2}, PlotLabel -> "B(axis) of 'loose' solenoid"]
This is intentionally wiggly; not a very good solenoid. An estimation
exercise would be to guesstimate the area under the curve by means of a
rectangle. By eyeball, try 6.1 (height) from 0.2 to 0.8 = 3.7
Here's a rectangle with a height of 6.2 and going from 0 to 0.85. Then
we'll plot it with the g function. This requires the Heaviside (step) function.
Define the Heaviside function.
Heaviside[x_] = If[x > 0, 1,0]
rect = 62/10*(Heaviside[z - 1/100] - Heaviside[z- 85/100]) Plot[{rect,1*10^6*g},{z,-1,2}, PlotLabel -> "Area estimation via rectangle"]
6.2*0.85
Lets integrate and see how good this is
Integrate[(1*10^6)*g, {z,-5,5}]//N
Consider a current loop of radius R carrying a current I, located in
the xy plane, with the current counter-clockwise from the x-axis to the
y-axis.
a) Use the Biot-Savart law to show that the z component of the magnetic
field at a point (0,0,z) on the axis of the loop is given by B_z = (u_o
I /2) R^2/(z^2+R^2)^(3/2). (You may wish to modify your work on the circloop
problem).
b) Find the value of z for where the dB_z/dz is a maximum or a minimum.
(This means that the second derivative of B_z is zero.) Call this value
z_o.
c) Now locate an identical coil at a distance of 2 z_o from the first,
and write down the total magnetic field as a function of z for the two
coils. (Note: coils like this are referred to as 'helmholtz coils'.)
d) Show that the first three derivatives of B_z will vanish at z=z_o for
the pair of coils.
Solution
Load the necessary packages.
Needs["Calculus`VectorAnalysis`"]
Part A
Vector to point on z axis
P = {0,0,z}
Vector to point on wire loop
s = {R*Cos[theta],R*Sin[theta],0}
Direction around wire loop.
ds = D[s,theta]
Vector from loop to 3D point.
r = P-s
Biot-Savart Law
dB = mu0*i*CrossProduct[ds,r]/(4*Pi*Sqrt[Dot[r,r]]^3)
Integrate around the loop to find B.
sol = Integrate[dB,{theta,0,2*Pi}]
Pull out the z component of the vector.
Bz = sol[[3]]
Part B
Take the second derivative of Bz to find where the first derivative of
Bz has maximums and minimums.
ddBz = D[Bz,{z,2}]
Find where the second derivative is 0.
sol = Solve[ddBz == 0, z]//Flatten
Pick the positive solution for z0.
z0 = sol[[2,2]]
Part C
Position second coil a distance 2*z0 from the first coil.
Bz2 = Bz/.{z -> z - 2*z0}
Bztot = Bz+Bz2
Part D
Take the first, second, and third derivatives of Bztot.
dBztot = D[Bztot,z]
ddBztot = D[Bztot,{z,2}]
dddBztot = D[Bztot,{z,3}]
First derivative goes to 0 at z = z0
dBztot = dBztot/.z -> z0
Second derivative goes to 0 at z = z0
ddBztot = ddBztot/.z -> z0//Simplify
Third derivative goes to 0 at z = z0
dddBztot = dddBztot/.z -> z0//Simplify
(a) Create a three dimensional contour plot of the electric potential
due to three point charges each with magnitude 2.00 µC located at
positions (-0.50 m, 0), (+0.50 m, 0), and (0,+0.75 m). The first two charges
are positive, the third is negative.
(b) Visually locate any points where a fourth positive test charge would
be in equilibrium. State whether the equilibrium is stable or unstable.
(c) Find the magnitude of the potential at (0, 0.50 m).
(d) Calculate the electric field and find where its x and y components
are both zero.
Part A
Clear["Global`*"]
Off[General::spell1]
Charge of the particle
q =2*10^(-7)*8.99*10^(9)
Potential function and electric field x-component
v = q/Sqrt[(x-a)^2+(y-b)^2]
Ex = D[v,x]//Simplify
Potential due to 3 charges; note subtraction to make 3rd charge
negative
pot1 = v/.{a -> -1/2, b -> 0};
pot2 = v/.{a -> 1/2, b -> 0};
pot3 = v/.{a -> 0, b -> 3/4};
pot3charges = pot1 + pot2 - pot3
ContourPlot[pot3charges,{x,-1,1},{y,-1,1.5}, ContourSmoothing -> 80,
PlotLabel -> "3D contour plot of electric potential", FrameLabel
-> {"X","Y"}, Contours -> 20]
Part C
Find the potential at (0,0.5)
sub = pot3charges/.{x -> 0, y -> 1/2}//N
Part D
Since dV = -Ex dx -Ey dy, when dy = 0 [no change
in y], Ex = -dV/dx Extot = -D[pot3charges,x]//Simplify
and when dx = 0 [no change in x], Ey = -dV/dy
Eytot = -D[pot3charges,y]//Simplify
Part E
Find where E field is zero
FindRoot[{Extot == 0, Eytot == 0},{x,0},{y,0}, MaxIterations
-> 50] FindRoot[{Extot == 0, Eytot == 0},{x,0},{y,1}, MaxIterations
-> 50]