Physics – Elektromagnetisme http://elektromagnetisme.no The home of FYS1120 Mon, 20 Oct 2014 11:23:54 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.3 28429679 Old exam problems http://elektromagnetisme.no/2013/11/21/old-exam-problems/ http://elektromagnetisme.no/2013/11/21/old-exam-problems/#comments Thu, 21 Nov 2013 13:45:01 +0000 http://elektromagnetisme.no/?p=2415 We have compiled a zip-file with a bunch of old exams, as well as their solutions. The newer ones, 2011 and 2012, are most relevant.

Good luck!

]]>
http://elektromagnetisme.no/2013/11/21/old-exam-problems/feed/ 6 2415
Exercises for Midterm Exam – Magnetism http://elektromagnetisme.no/2013/09/30/exercises-for-midterm-exam-magnetism/ http://elektromagnetisme.no/2013/09/30/exercises-for-midterm-exam-magnetism/#comments Mon, 30 Sep 2013 10:47:10 +0000 http://elektromagnetisme.no/?p=2292 Continue reading ]]> Since the lectures and the weekly exercises are not completely in sync, we are adding a couple of exercises which we recommend you to go through before the midterm exam.

]]>
http://elektromagnetisme.no/2013/09/30/exercises-for-midterm-exam-magnetism/feed/ 2 2292
Optional exercises in vector analysis http://elektromagnetisme.no/2013/09/20/optional-exercises-in-vector-analysis/ http://elektromagnetisme.no/2013/09/20/optional-exercises-in-vector-analysis/#respond Fri, 20 Sep 2013 10:18:05 +0000 http://elektromagnetisme.no/?p=2236 Continue reading ]]> If you feel that you need more training in vector analysis, consider doing these exercises that we have borrowed from D. J. Griffiths’ book “Introduction to Electrodynamics”. If you feel that you have mastered the weekly exercises this far without getting stuck on the vector calculations, feel free to skip this problem set.

Most of these problems come without solutions, but you can test your understanding at the group sessions.

]]>
http://elektromagnetisme.no/2013/09/20/optional-exercises-in-vector-analysis/feed/ 0 2236
Electric field lines http://elektromagnetisme.no/2012/09/05/electric-field-lines/ http://elektromagnetisme.no/2012/09/05/electric-field-lines/#respond Wed, 05 Sep 2012 19:31:12 +0000 http://elektromagnetisme.no/?p=1423 Continue reading ]]> We have made a small demo that will allow you to play around with electric field lines in your web browser. You can place and move around charged particles to see how the field changes as you make your own charge configuration.

An electric field line simulator straight in your browser!

Try the simulator here

Note that there are some limitations to this simulation, leaving it a bit unphysical when it comes to lines that might end up in open space, wrong field line density and other quirks. All in all it should be correct to a decent approximation, though.

For the programming enthusiasts out there, the simulation is created using Javascript and HTML5. You can check out the source code here.

Enjoy!

]]>
http://elektromagnetisme.no/2012/09/05/electric-field-lines/feed/ 0 1423
Classical mechanics in HTML5 and Javascript Mon, 26 Mar 2012 20:22:42 +0000 http://dragly.org/?p=685 Continue reading ]]> Ok, so we’re working on the home exam in classical mechanics and I decided to spend some time simulating the solution of the first exercise. Probably not the wisest way to spend time during an home exam, but what the heck. I’m learning some Javascript and HTML5, plus the fact that it’s always fun to verify results by looking at something moving!

So here you go. A pendulum on a cart.

I won’t go into details about deriving and solving the Lagrange equation for this system now, but I might get back to that at a later time. And of course there will be some added controls to this so you could set the initial positions, velocities and stuff. Sometime later, I hope.

]]>
1124
Note on the magnetic vector potential http://elektromagnetisme.no/2011/10/27/note-on-the-magnetic-vector-potential/ http://elektromagnetisme.no/2011/10/27/note-on-the-magnetic-vector-potential/#respond Wed, 26 Oct 2011 22:29:56 +0000 http://mindseye.no/?p=992 Continue reading ]]>

Magnetic dipole (Source: Wikipedia*)

In electrostatics we found it very convenient to introduce the concept of the electric potential. It gave us a straight forward way of calculating electric fields without doing any vector calculations or using any symmetry arguments. Can we introduce something similar for magnetic fields?  It turns out that because magnetic fields are divergence less we can find a vector potential who’s curl gives us the magnetic field! Even though this magnetic vector potential is not as useful as the electrostatic potential in elementary applications, it turns out to be of major importance in electrodynamics as well as classical mechanics and quantum mechanics. It might therefore be a good idea to get familiar with the concept and some of it’s properties already, especially if you are taking a degree in physics. In this note I explain how to find the vector potential, the concept of a gauge transformation and it’s fundamental equations relating it to currents in both electrostatics and electrodynamics. Read more here:

* Image found at http://en.wikipedia.org/wiki/File:VFPt_dipole_magnetic3.svg / CC BY-SA 3.0

]]>
http://elektromagnetisme.no/2011/10/27/note-on-the-magnetic-vector-potential/feed/ 0 992
Nanoparticles: An after-exam bonus http://elektromagnetisme.no/2011/10/14/nanoparticles-an-after-exam-bonus/ http://elektromagnetisme.no/2011/10/14/nanoparticles-an-after-exam-bonus/#respond Fri, 14 Oct 2011 08:39:40 +0000 http://mindseye.no/?p=946 Continue reading ]]> I guess you are pretty exhausted after the midterm exam this week and a lot of you have probably had other exams to deal with as well. What better time to share a game with you to put your minds at ease for a little while.

The game is called Nanoparticles and was written by me about half a year ago. It is based on Coulomb’s law with a few modifications and Newtonian physics. But instead of having you calculate anything, the game does it all for you in the background. You can download the game for Ubuntu, Linux, Windows and Nokia phones here (Mac and Android versions will be available sometime in the future):

Download Nanoparticles

Your mission is to make sure the positive particles you control does not crash into the negative ones. That would cause it to annihilate. To do this, you need to place out other positive and negative particles to keep your particle away for as long as possible.

The game is also open source, so if you’re interested in programming and C++, you can have a look at the source code too. More information about the game and how to obtain the source code is found here.

]]>
http://elektromagnetisme.no/2011/10/14/nanoparticles-an-after-exam-bonus/feed/ 0 946
On the concept of dipole moment http://elektromagnetisme.no/2011/09/05/on-the-concept-of-dipole-moment/ http://elektromagnetisme.no/2011/09/05/on-the-concept-of-dipole-moment/#respond Mon, 05 Sep 2011 08:46:09 +0000 http://mindseye.no/?p=771 Continue reading ]]> The dipole moment of a configuration of charges is an important concept in electromagnetism, but in most introductory texts it might seem like the dipole moment is only defined for two opposite point charges separated by a distance. This is however not the case. The dipole moment can be defined for any configuration of charges where the net charge is zero.

H20 is a polar molecule which means that it has dipole moment. However the H20 molecule is not just two point charges separated by a distance. So how do we then define its dipole moment? Source: Qwerter/Wikipedia

The dipole moment is also crucial in order to undersant how molecules and atoms are affected when they are placed in electric fields as well as understanding the phenomenon of “polarization” of matter.

If you want to learn more about why dipole moments are important and about its generality the following note might be of interest to you:

 

]]>
http://elektromagnetisme.no/2011/09/05/on-the-concept-of-dipole-moment/feed/ 0 771
Animating plots and waves in Python using matplotlib http://elektromagnetisme.no/2011/04/03/animating-plots-and-waves-in-python-using-matplotlib/ http://elektromagnetisme.no/2011/04/03/animating-plots-and-waves-in-python-using-matplotlib/#comments Sun, 03 Apr 2011 16:34:14 +0000 http://mindseye.no/?p=393 Continue reading ]]> matplotlib is an amazing framework to do visual plots in Python. It compares well with GnuPlot and beats Matlab’s plotting abilities by having more features. Although it does lack some 3D support, you may simply choose a different framework for 3D plots thanks to Python’s flexibility . In which case I would recommend Mayavi as a superb 3D plotting engine which I have written about before.

But now, let’s have a look at matplotlib’s animation capabilities. The script below shows a very easy approach to animation in matplotlib. This results in an animation of the standing wave shown here:

The script is as follows:

from matplotlib.pylab import *  # pylab is the easiest approach to any plotting
import time                     # we'll do this rendering i real time

ion()                           # interaction mode needs to be turned off

x = arange(0,2*pi,0.01)         # we'll create an x-axis from 0 to 2 pi
line, = plot(x,x)               # this is our initial plot, and does nothing
line.axes.set_ylim(-3,3)        # set the range for our plot

starttime = time.time()         # this is our start time
t = 0                           # this is our relative start time

while(t < 5.0):                 # we'll limit ourselves to 5 seconds.
                                # set this to while(True) if you want to loop forever
    t = time.time() - starttime # find out how long the script has been running
    y = -2*sin(x)*sin(t)        # just a function for a standing wave
                                # replace this with any function you want to animate
                                # for instance, y = sin(x-t)

    line.set_ydata(y)           # update the plot data
    draw()                      # redraw the canvas

I’ve commented each line, since the script is fairly small, but let’s outline a few important things.

First of all, you need to disable interactive mode with

ion()

This makes it possible to animate, but disables all the button controls in matplotlib’s figure window.

Furthermore, we need to assign our plot to a variable (or pointer if you like), named line. This is done by plotting some dummy data:

line, = plot(x,x)

Note the comma after “line”. This is placed here because plot returns a list of lines that are drawn. Since we draw only one line we unpack only this by placing a comma and nothing else after “line”. If you plot multiple lines at once you may unpack them together by issuing a command like this:

line_a,line_b,line_c = plot(...

This plotting makes our axes aligned to the dummy data (in this case y = x). To make sure we have enough room, we manually set the limits of our y axis:

line.axes.set_ylim(-3,3)

Finally, we do our calculations and eventually change the y-data for each time step. After this, we draw everything back onto the canvas. This is done through the following two lines:

    line.set_ydata(y)           # update the plot data
    draw()                      # redraw the canvas

That’s it. Your animation should now look like the one above.

Saving the animation to a  file

Saving everything to file is fairly simple with the savefig command. You can save all the frames as images and then convert them to video using your favorite video editor. I recommend using ffmpeg from command line or Blender (which also does 3D). There are surely easier tools out there, but I find the work flow using ffmpeg and Blender quite quick, and they are also useful tools for many other tasks.

I’ve made the script animation ready below, and there’s really just one important thing to note: Earlier we showed the animation in real time. Saving all the images in real time lags badly and many frames are dropped. Because of this, we now set a delta time between each frame and iterates over each and every frame to make sure we have enough data for a smooth video.

Feel free to use the script below as it suits you:

from matplotlib.pylab import *  # pylab is the easiest approach to any plotting

ion()                           # interaction mode needs to be turned off

fig = figure(figsize=(16,9),dpi=80)     # create a figure in 1280 x 720 pixels
                                # this is not as simple as it could be, but
                                # it is like this because matplotlib is focused
                                # on print, not screen

x = arange(0,2*pi,0.01)         # we'll create an x-axis from 0 to 2 pi
line, = plot(x,x)               # this is our initial plot, and does nothing
line.axes.set_ylim(-3,3)        # set the range for our plot

t = 0                           # this is our relative start time
dt = 0.04
i = 0
while(t < 5.0):                 # we'll limit ourselves to 5 seconds.
                                # set this to while(True) if you want to loop forever
    y = -2*sin(x)*sin(t)        # just a function for a standing wave
                                # replace this with any function you want to animate
                                # for instance, y = sin(x-t)

    line.set_ydata(y)           # update the plot data
    draw()                      # redraw the canvas

    t = t + dt                  # increase the time
    i = i + 1                   # increase our counter

    # save the figure with a 4-digit number
    savefig("outdata/blah" + '%04d' % i + ".png")
]]>
http://elektromagnetisme.no/2011/04/03/animating-plots-and-waves-in-python-using-matplotlib/feed/ 6 393
Using binary data instead of text files in Python http://elektromagnetisme.no/2010/11/23/using-binary-data-instead-of-text-files-in-python/ http://elektromagnetisme.no/2010/11/23/using-binary-data-instead-of-text-files-in-python/#respond Tue, 23 Nov 2010 20:33:51 +0000 http://mindseye.no/?p=360 Continue reading ]]> It’s been a while since we’ve posted anything here. Sorry about that. It has just been too much to do lately to find the time to write new posts.

This post is also arriving a bit late to be useful for anyone this semester, but what it shows might be useful for others. Or maybe for someone taking the FYS1120 course at a later time. So I’ll post it here still.

In mandatory exercise 2 we needed to load a huge file containing data from an AM radio signal. This was available a Matlab file and as a text file with all the values on each row. Those of us using Python realized quite quickly that most of the time spent on this exercise went to load the data before performing any computations on the data.

However, in proper hindsight, I thought it might have been a better idea to save the file as binary data instead of as a text file. After all, binary data saves space and usually is a bit quicker to load.

Doing this in NumPy is extremely simple. Just load the text file data and save it back in NumPy’s binary format:

from numpy import *
data = loadtxt("input_data.txt")
save("binary_data.npy", data)

Now, loading the file in your application is just as simple:

from numpy import *
data = load("binary_data.npy")

The time you’ll save on doing this for large data sets is extreme. Loading the data set we recieved in mandatory exercise 2 as a text file took me about 2 minutes and 21 seconds, while loading the data from the binary file format took only 0.06 seconds! Yes, that is 60 milliseconds.

On top of this, loading the data as text using “loadtxt” practically wasted 2 GB of memory on my computer, while loading it as a binary file used only about one hundred megabytes; just about the size of the binary data file.

Now I just wish I thought of this a couple of weeks earlier. But I guess that is what hindsight is for.

]]>
http://elektromagnetisme.no/2010/11/23/using-binary-data-instead-of-text-files-in-python/feed/ 0 360