Application Center - Maplesoft

App Preview:

Animation of the Motion of a Charged Particle Under an Electric Field

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

motion_under_field.mws

Animation of the Motion of a Charged Particle
Under an Electric Field

Pauline Hong
Duke University
pauline.hong@duke.edu

Hello: The Problem

All my life I have heard this piece of wisdom: Gain some intuition about the solution to your problem before you hurry to tackle it.  You will avoid frustrating hours filled with headaches, no smiles and desires to simply pull out all your hair.  I have learned that this applies to all aspects of my life, even to my physics homework.

Suppose you have one or more stationary charged particles on a plane.  These stationary particles produce an electric field at all points on the plane.  Let us place a moving charged particle on this plane.  The moving particle will experience a force exerted by the electric field, causing it to accelerate.  Will it move, and if it does, where will it move?  I have always struggled to draw a mental picture of how I expect P will behave under the electric field before actually turning to my pencil and paper to do the calculations.

That's why I wrote a simple program using Maple 6 to help me gain the intuition that I lack.  The program will produce an animation of the motion of a charged particle under an electric field.  Here I would like to share my program with you, and hopefully it will help you gain some intuition too!

Time to Recall: The Physics

Hmm... a disclaimer first:  In the following I will assume that the acceleration of the charged particle is negligible.  Therefore, we will safely ignore the effects of magnetic fields, electromagnetic induction, saving me from physics induced migraine headache.  The end of the disclaimer.

Still with me?  Good.  The main idea is as follows:

  • The stationary particles produce an electric field everywhere in space.
    The electric field
    E  generated by a charge Q  at a position with distance r  from the charge is given by E = k*Q/(r^2)  where k = .899e10  and the direction is along the line connecting the charge and the position.  The electric field generated by several charges is the vector sum of the field generated by each charge.  (This is the so called Coulomb's Law.)
  • The electric field exerts a force on the moving particle.
    Let E  be the electric field at a position.  Then the force F  experienced by a charge q  at that position is obviously given by F = q*E .  (This is also Coulomb's Law.)
  • The force accelerates the particle.
    The acceleration a  of a particle of mass m  under a force F  is given by a = F/m .  (Of course, this is Newton's Second Law of Motion.)
  • The acceleration causes a change in position and velocity.
    Treating the acceleration as constant during a small period of time, we can use the following constant acceleration equations from kinematics:
    p[f] = p[i]+v[i]*Delta*t+a*(Delta*t)^2/2
    v[f] = v[i]+a*Delta*t
    where
    a  is the acceleration, Delta*t  is the small change in time, p[i]  is the initial position, p[f]  is the final position, v[i]  is the initial velocity and v[f]  is the final velocity.  You have to apply these to both the x  component and the y  component.

Time to Program: The Code

The programs are structured in top-down fashion: the main routine is at the top followed by its subroutines.

>    restart:

#=====================================================
move_particle := proc(M,S,T)
#=====================================================
  local num_frames,num_moves_per_frame,n,dt,
        movements,xmin,xmax,ymin,ymax,qmax,
        plot_background,plot_legend,plot_stationary,plot_movements;

  num_frames := 20;
  num_moves_per_frame := 5;
  n := num_frames*num_moves_per_frame;
  dt := T / n;

  movements := compute_movements(M,S,dt,n);
  compute_bounds(movements,M[2],S,
                 'radius','xmin','xmax','ymin','ymax','qmax');

  plot_background := draw_background(xmin,xmax,ymin,ymax);
  plot_legend     := draw_legend(xmin,xmax,ymin,ymax,qmax);
  plot_stationary := draw_stationary(S,radius,qmax);
  plot_movements  := draw_movements(movements,radius,qmax,M[2],num_moves_per_frame);

  plots[display]([plot_movements,plot_stationary,plot_legend,plot_background],
                 scaling=constrained,axes=none,
                 title=`Movement of a Charged Particle Under an Electric Field`,
                 titlefont=[TIMES,BOLD,12]);
end:

#=====================================================
compute_movements := proc(M,S,dt,n)
#=====================================================
  local m,q,config,movements,i;

  m  := M[1];
  q  := M[2];
  config     := M[3..6];
  movements  := config[1..2];

  for i from 1 by 1 to n do
    config    := compute_a_movement(q,m,config,S,dt);
    movements := movements,config[1..2];
  od;

  return [movements];
end:

#=====================================================
compute_a_movement := proc(q,m,C,S,dt)
#=====================================================
  local px,py,vx,vy,Enet,Fnetx,Fnety,
        ax,ay,dpx,dpy,new_px,new_py,new_vx,new_vy;

  px := C[1];
  py := C[2];
  vx := C[3];
  vy := C[4];

  Enet := compute_electric_field(px,py,S);

  Fnetx := Enet[1]*q;
  Fnety := Enet[2]*q;

  ax := Fnetx/m;
  ay := Fnety/m;

  dpx := vx*dt + 1/2*ax*dt*dt;
  dpy := vy*dt + 1/2*ay*dt*dt;

  new_px := px + dpx;
  new_py := py + dpy;

  new_vx := vx + ax*dt;
  new_vy := vy + ay*dt;

  return [new_px,new_py,new_vx,new_vy];
end:

#=====================================================
compute_electric_field := proc(px,py,S)
#=====================================================
  local Enetx,Enety,s,dx,dy,r,c;

  Enetx := 0.0;
  Enety := 0.0;

  for s in S do
    dx := px-s[2];
    dy := py-s[3];

    r  := sqrt(dx*dx + dy*dy);
    c  := 8.99E9*s[1] / (r*r*r);

    Enetx := Enetx + c * dx;
    Enety := Enety + c * dy;
  od;

  return [Enetx,Enety];
end:

#=====================================================
compute_bounds := proc(movements,q,S,radiusp,xminp,xmaxp,yminp,ymaxp,qmaxp)
#=====================================================
  local movement,s,side_length,xcenter,ycenter,
        radius,xmin,xmax,ymin,ymax,qmax;

  xmin := movements[1][1];
  xmax := movements[1][1];
  ymin := movements[1][2];
  ymax := movements[1][2];

  for movement in movements do
    xmin := min(xmin,movement[1]);
    xmax := max(xmax,movement[1]);
    ymin := min(ymin,movement[2]);
    ymax := max(ymax,movement[2]);
  od;

  for s in S do
    xmin := min(xmin,s[2]);
    xmax := max(xmax,s[2]);
    ymin := min(ymin,s[3]);
    ymax := max(ymax,s[3]);
  od;

  side_length  := max(abs(xmax-xmin),abs(ymax-ymin))/(1-4/30);
  radius       := side_length/30;
  xcenter      := (xmin+xmax)/2;
  ycenter      := (ymin+ymax)/2;
  xmin := xcenter-side_length/2;
  xmax := xcenter+side_length/2;
  ymin := ycenter-side_length/2;
  ymax := ycenter+side_length/2;

  qmax := abs(q);
  for s in S do
    qmax := max(qmax,abs(s[1]));
  od;

  radiusp := radius;
  xminp   := xmin;
  xmaxp   := xmax;
  yminp   := ymin;
  ymaxp   := ymax;
  qmaxp   := qmax;

  return;
end:

#=====================================================
draw_background := proc(xmin,xmax,ymin,ymax)
#=====================================================
  return plottools[rectangle]([xmin,ymax],[xmax,ymin],color=black);
end:

#=====================================================
draw_legend := proc(xmin,xmax,ymin,ymax,qmax)
#=====================================================
  local k,width,plot_legend,i,c;

  k := 18;
  width := (xmax-xmin)/k;

  plot_legend := TEXT([xmin-width,ymin-width],`-`,
                      FONT(COURIER,BOLD,11)),
                 TEXT([xmax+width,ymin-width],`+`,
                      FONT(COURIER,BOLD,11));

  for i from 1 to k do
    c := get_color(qmax,-qmax+2*qmax/(k-1)*(i-1));
    plot_legend := plot_legend,plottools[rectangle]([xmin+width*(i-1),ymin-width/2],
                                                    [xmin+width*i,    ymin-width/2*3],
                                                    color=c);
  od;

  return plot_legend;
end:

#=====================================================
draw_stationary := proc(S,radius,qmax)
#=====================================================
  local plot_stationary,s;

  plot_stationary := [];
  for s in S do
    plot_stationary := [op(plot_stationary),
                        plottools[disk]([s[2],s[3]],radius,color=get_color(qmax,s[1]))];
  od;

  return PLOT(op(plot_stationary));
end:

#=====================================================
draw_movements := proc(movements,radius,qmax,q,num_moves_per_frame)
#=====================================================
  local D,plot_movements,i;

  D := plottools[disk]([0,0],radius,color=get_color(qmax,q));
  plot_movements := [];

  for i from 1 by num_moves_per_frame to nops(movements) do
    plot_movements := [op(plot_movements),
                       [shift_disk(D,movements[i][1],movements[i][2])]];
  od;

  return PLOT(ANIMATE(op(plot_movements)));
end:

#=====================================================
shift_disk := proc(D,x,y)
#=====================================================
  return POLYGONS(map(xy -> [xy[1]+x,xy[2]+y],op(1,D)),op(2,D));
end:

#=====================================================
get_color := proc(qmax,q)
#=====================================================
  local color;

  if q > 0 then
    color := COLOR(RGB,1,1-q/qmax,0)
  else
    color := COLOR(RGB,0,1-abs(q)/qmax,1)
  fi;

  return color;
end:

Time to Play: The Examples

How to use the program

The main procedure you will use is called move_particle .  It takes the following arguments:

  • M: moving particle information = [mass, charge, initial x position, initial y position, initial x velocity, initial y velocity]
  • S: stationary particles informations = [[charge1, initial x position1, initial y position1], [charge2, initial x position2, initial y position2], ...]
  • T: time interval

Repelling particles

>    move_particle([0.000001, 80E-9, 100.0, -50.0, -2.0, 1.5],[[400E-9, 0.0, 0.0]], 100);

[Maple Plot]

Attracting particles

>    move_particle([0.0000001, -20E-9, 200.0, 0.0, 0.0, 1.0],[[200E-9, 0.0, 0.0]], 600);

[Maple Plot]

Weeee!  :-)

>    move_particle([0.001, 10E-9, 2.0, 2.0, 0.0, 0.0],[[ 25E-9, 0.0, 0.0],[-15E-9, 2.0, 0.0],[-30E-9, 1.5, -2.0]], 200);

[Maple Plot]

Challenge for you!

Can you make the moving particle trace the outline of the Maple logo approximately?

>   

>   

Bye bye: The Final Thoughts

Yay!  I have accomplished my goal: To create an animation using Maple that would help me gain some intuition about how particles behave under an electric field.

I hope my program has helped you gain some intuition about the solution to your problem before you hurried to tackle it!

Disclaimer:  While every effort has been made to validate the solutions in this worksheet, Waterloo Maple Inc. and the contributors are not responsible for any errors contained and are not liable for any damages resulting from the use of this material.