Computer Lab 5: Lecture 14

In our computer lab lectures we will work together through concepts and challanges we have discussed over the week in class.  As with your after-class Exercises, you will be expected to turn in your computer lab notebooks before the nect lecture. Please do so by e-mailing your completed *nb file to Lan Yu (ece329.uiuc@gmail.com), make sure you name the file using the following notation: “Exn_Last_First.nb”, where n is the Lecture number (in this case, 14), and First and Last would be your first and last name.  So my submission to Lan for this computer lab would be titled “Ex14_Wasserman_Dan.nb”.  You will receive full credit for your computer lab if it is turned in before the next lecture (Lecture n+1).  For this Computer Lab you will need to submit BOTH your “Ex14_Wasserman_Dan.nb” and your “Wasserman_Dan_CDF.cdf” files.  No late submissions will be accepted.

Objective/Overview:

In class this week we were introduced to magnetic fields.  We learned that magnetic fields are caused by currents, and can exert a force on moving charges.  We determined that we can calculate the magnetic field from an infinite wire (straight line), as well as from an current carrying wire of arbitrary shape, using the Biot Savart Law.  We also showed that Ampere’s Law allows us to calculate magnetic fields for current distributions with certain symmetries, in a very similar way to how we can use Gauss’s Law to calculate electric or displacement fields.  In our last exercise, you also got to see how changes in magnetic field can induce electromotive forces (emf) on wire loops.  In today’s exercise, we are going to go back to looking at loops, but this time we are going to assume we have a current flowing in the loop(s), and then calculate the resulting magnetic field.

Calculating the Magnetic Field from a single Current Loop (Using BS Law)

We know we can calculate the magnetic field from any current carrying wire using the Biot-Savart Law:
d(OverVector[B])=(((Subscript[μ, o])I)/(4π))((d(OverVector[l])×(OverVector[r]))/(r^3))=(((Subscript[μ, o])I)/(4π))((d(OverVector[l])×(OverHat[r]))/(r^2))
We need to find the magnetic field from a loop of current, so let’s say that our loop is on the xy plane, with the z-axis going through the center of the loop and a loop radius of ro.  We are basically going to have to take a line integral around the loop.  Our loop is defined by:

ClearAll[ropath,ro,dropath,po,bloop,r]

ropath[ro_]:={ro*Cos[2*Pi*t],ro*Sin[2*Pi*t],0}

ropath[ro]

our d(OverVector[l])is then just:

dropath[ro_]:=D[ropath[ro],t]

dropath[ro]

Now we need to integrate around this loop, with (OverVector[r])={(Subscript[x, o]),(Subscript[y, o]),(Subscript[z, o]))=-{ro Cos[2 π t],ro Sin[2 π t],0},  d(OverVector[l])=dropath, and let’s set (((Subscript[μ, o])I)/(4π))=1 and ro=1.  Let’s stay in the xz plane to simplify things...

po={xo,0,zo}

r=po-ropath[1]

rhat=Normalize[r]

rhat={((xo-Cos[2 π t])/(Sqrt[(((zo))^2)+(((xo-Cos[2 π t]))^2)+(((Sin[2 π t]))^2)])),-((Sin[2 π t])/(Sqrt[(((zo))^2)+(((xo-Cos[2 π t]))^2)+(((Sin[2 π t]))^2)])),(zo/(Sqrt[(((zo))^2)+(((xo-Cos[2 π t]))^2)+(((Sin[2 π t]))^2)]))}

We now have everything we need to solve the integral which will give us B(xo,zo).  Unfortunately, this will hang Mathematica.  It doesn’t like the integral.  But we can solve for certain values of xo, zo using the following syntax:

bloop[x_,z_]:=NIntegrate[Cross[dropath[1],rhat]/Dot[r,r]/.{xo->x,zo->z},{t,0,1},AccuracyGoal->8]

Can we plot this along some lines, say the z-axis?

DiscretePlot[bloop[0,z][[3]],{z,-2,2,.1}]

The plot above shows the z-component of B as a function of position along the z-axis.  This is actually an integral that can be done analytically.
What about (Subscript[B, z]) along the x-axis?

DiscretePlot[bloop[x,0][[3]],{x,0,1.5,.15}]

Note that I have tried to avoid xo=+/-1, where B diverges...Nonetheless, this still took a pretty long time.  We see that across the x axis, our B field is pretty much constant inside the loop (ignoring the divergence at xo=+/-1), and ~0 outside!!  Also, bear in mind that if we want to find the field at any point in 3D space, we can recognize that this is a symmetric structure, so all that matters will be the distance from the z axis and the distance above the xy plane.
Trying to take the integral symbolically is a total mess!  It requires Elliptical Integrals and Mathematica slows to a crawl.
Even with the faster NIntegrate command, it will still be incredibly difficult to produce even a VectorPlot for this system.  We can try to do so, as long as we don’t use too many points...

v1=Table[{{x,z},bloop[x,z][[{1,3}]]},{x,0,1.5,.15},{z,-.5,1.5,.25}]

ListVectorPlot[v1]

This wasn’t easy, but we were able to plot the magnetic field from a single loop.  You will notice that the vector plot has a MUCH higher density than our table.  Clearly Mathematica has interpolated the table to create a denser array of data points.  Below are plotted only the points in the table:

ListVectorPlot[v1,VectorPoints->All]

Calculating the Magnetic Field from More than One Current Loop (Using BS Law)

What about more than one loop? Well, we know that magnetic fields can be superpositioned, so all we need to do is add the field from our single loop to the field from another loop, but shifted...Of course, if we perform the integrals above for each point, for each loop, we are adding a lot of time to the calculation.  On the other hand, if we take the table, and shift the table, we are losing a lot of resolution...
Let’s start by simply adding a second loop, at z=.5.

DiscretePlot[bloop[0,z][[3]]+bloop[0,z-0.5][[3]],{z,-2,2,.1}]

Can we do a vector plot of this?  Well, it’s going to get slow, quickly, but we can try...

v2=Table[{{x,z},bloop[x,z][[{1,3}]]+bloop[x,z-0.5][[{1,3}]]},{x,0,1.5,.15},{z,-.5,1.5,.25}]

Oof.  That is brutal.  But it works!

ListVectorPlot[v2]

If we want to create a solenoid, then all we have to do is add the fields from a series of shifted single loops!  But we have already seen how long it takes to do 2 loops, it is going to get unwieldy quickly. Try to see if you can model the field from a Solenoid with 6 loops equally spaced between z=0 and 1.

v6=

ListVectorPlot[v6]

What does the z-component of the B-field look like along the z-axis?

Let’s ONLY consider the B-field at the z-axis, and let’s try to design a solenoid that has UNIFORM Bz along the z-axis for at least some distance...

vn[dz_,N_]:=DiscretePlot[Sum[bloop[0,z-i*dz][[3]],{i,0,N}],{z,-0.5,N*dz+0.5,dz}]

vn[0.5,40]

After playing around with your inputs, you will start to see that in order to get a uniform Bz, you need the length of the solenoid to be >> r!

Our First CDF!

In our previous Computer Lab Lecture, we showed how we could develop plots that we could manipulate in real time.  The next logical step is to create a CDF, or Computable Document Format, file which can act as a stand-alone file (or an html file), which allows real time manipulation of the system under study.
To do this, we are going to open a new file, where we will again play around with the summation of cosines.  
Once you have created the file with the summation of Cosines, and if you have time, go ahead and create an additional CDF file that illuminates some aspect of today’s lecture.  This could be a CDF that plots Bz vs z for varying current, loops, and loop density, or a CDF that shows the vector field from a single loop, as a function of radius and current, to give just two examples. Of course, feel free to copy the code from this notebook as needed!