[Charged particles produce an electric field.]

Week 9 Notes: Scalar and Vector Fields

We study scalar and vector fields in 2D and learn how to solve Laplace's equation using the relaxation method.

Charged Particles Electric Field

The electric field from a collection of positive and negative charges is shown in the Charged Particles Electric Field Model. The model computes the sum of the electric field components using the known the locations of the charges and the locations of the grid points.

 

for(int i=0; i<m; i++) {                         // loop over grid x
  double xi= _view.vectorField.indexToX(i);      // x-coordinate of grid point
  for(int j=0; j<m; j++) {                       // loop over grid y
    double yj= _view.vectorField.indexToY(j);    // y-coordinate of grid point
    ex[i][j]=ey[i][j]=0;                         // zero field components 
    mag[i][j]=0;                                 // zero magnitude
    for(int p=0; p<n; p++) {                     // loop over charges
      double dx=xi-x[p];                         // x-separation from grid point
      double dy=yj-y[p];                         // y-separation from grid point
      double r2=dx*dx+dy*dy;                     // charge to grid point distance squared
      double r3=r2*Math.sqrt(r2);                // charge to grid point distance cubed
      if(r2==0) continue;                         // check for singularity
      ex[i][j]+=q[p]*dx/r3;
      ey[i][j]+=q[p]*dy/r3;
    } // end of charge loop
    mag[i][j]=Math.sqrt(ex[i][j]*ex[i][j]+ey[i][j]*ey[i][j]);
  } // end of y loop
} // end of x loop

The Fixed Relation code has three nested loops. The i-loop iterates through the grid's x-values and the j-loop iterates through the grid's y-values. The inner loop iterates over the charged particles qa with position (xa, ya), computes the distant to the grid point, and sums the point-charge electrostatic components at the (xi, yj) grid point. Run the model to see the field from other point charge configurations.  Note that you can drag the charges.

Related Models

The following EJS models demonstrate how to display two-dimensional scalar and vector fields using elements on the fields and plots tab on the EJS 2D Drawables palette.

Credits:

The Charged Particles Electric Field Model was created by Wolfgang Christian using the Easy Java Simulations (EJS) version 4.1 authoring and modeling tool.  You can examine and modify a compiled EJS model if you run the model (double click on the model's jar file), right-click within a plot, and select "Open Ejs Model" from the pop-up menu.  You must, of course, have EJS installed on your computer.

 

Information about Ejs is available at: <http://www.um.es/fem/Ejs/> and in the OSP comPADRE collection <http://www.compadre.org/OSP/>.