ECE LAB Solution



  1. Read through these LLaab #23 notes carefully, pay particular attention to the above introduction on numerical integration.

  1. Review the solution to the electric field at a point P(0, 0, z) above a uniformly charged circular ring of charge. The detailed, step by step solution has been posted as Coulomb’s

Law 2: E-field of a Uniformly Charged Ring under the Contents Example Problems Electrostatics section of the course website.

  1. Use Coulomb’s Law to set up the solution to the electric field at an arbitrary point P(x, y, z) of a uniformly charged, circular ring of charge centered about the origin and lying in the xy plane. Do not attempt to do the integrations! As has been done above for the finite-line charge, just come up with the three integrations you will have to do for the Ex, Ey, and Ez components of the total electric field at P(x, y, z). Write your solution in the box below:

  1. Create a MATLAB function called ringofcharge.m, that carries out the following tasks:

    1. Takes as inputs the radius of the ring (a), the uniform charge density (), the point location (x, y, and z), and the number of steps for the integration (N).

    1. Numerically evaluates the three one-dimensional integrations required to find the electric field components Ex, Ey, and Ez of the circular ring of charge at a point P(x, y, z). You cannot use any of the built-in MATLAB functions for doing this integration, such as quadl or trapz. These can be used to verify your own algorithm’s result, but cannot be used in your ringofcharge function.

    1. Calculates the magnitude of the total electric field at this point.

This means that your function should be able to return the values for Ex, Ey, Ez and Etot at any point, P(x, y, z), for any uniformly charged ring centered about the z – axis and lying in the

xy-plane. Your result from part 3) above should help, as well as the sample function lineofcharge.m shown in the introduction. Each student must submit their working code (i.e., debugged) by handwriting it in the box below. It is essential that you debug this code before you come to the lab, otherwise you will not finish the lab. You should keep an electronic copy of your code which you can run in the lab.

Make sure this portion of the lab is your own work!

  1. Answer the questions below. Electric Fields Along the z – axis

    1. What is the expression for the electric field at any point along the axis of a ring, which is uniformly charged ring (), has a radius a, lies in the xy plane and is centered about the origin (meaning the ring axis is the z-axis)?

    1. How could you make use of the expression written in part i) above, to verify your ringofcharge.m algorithm and code? Come up with a testing plan which includes at least two test cases that you will use in the lab session to make sure that your code is running properly. As a hint, one test case has been given to you.

Testing Plan:

Testing Cases:

Test Case #1:




m, and




Test Case #2:

Use these two test cases to help you debug your code, and verify that it is working correctly.

Testing Results:

Test Case #1:




m, and



̂, ̂

Test Case #2:

Electric Fields Along the y – axis

For a uniformly charged ring lying in the xy plane and centered about the origin, what component(s) of the electric field will be non-zero for points along the y – axis? Explain your reasoning.


Evaluation and Visualization of the Electric Field for a Charged Ring 1. Validating Your ringofcharge.m Function

To ensure that your function is properly calculating the electric field of a charged ring, do the following two exercises.

1.1. Electric Fields Along the z-axis

Now consider the case in which a uniformly-charged ring lies in the xy plane and is centered

about the z-axis. It has a radius of m and a total charge of mC.

Write another short function, plotringcharge.m, that calls your ringofcharge.m function to calculate the electric field components at points along the z – axis between z = 3 m and z = 3 m. Use N = 500 for your calculations.

  • This function should plot the calculated values of Ez along the z – axis and compare this to the theoretical values (Etheory), determined from the expression stated in your preparation (part 5).

  • Plot the theoretical values (Etheory) with a blue line, and the calculated values with red circles.

  • Properly label your axes, and include a legend in your figure (see help legend).

  • You should have at least 100 data points, but no more than 400. If these plots do not correspond, then you will have to correct your ringofcharge function.

1.2. Electric Fields Along the y – axis

Modify your plotringofcharge function to calculate and plot the electric field components Ex, Ey, and Ez, along the y axis from 0.1 m to 2 m. Again, the ring has a radius of

m and a total charge of mC.

  • Save this as a new function, as you will be asked to use the original plotringofcharge function again.

  • Use an N value of 500.

  • Verify that the correct component(s) are zero (or very close to zero), as you predicted in your preparation. Why are these components not exactly zero?

Before you leave, make sure to discuss the results of this section with your TA.

  1. Electric Fields for Non-uniformly Charged Rings, General Points, and Asymmetric Charge Distributions

2.1. Fields due to Non-uniform Charge Distributions

Modify your ringofcharge function so that you can calculate electric fields for non-uniform charge densities.

  • Then use your plotringofcharge function to plot Ex, Ey, and Ez along the z – axis, from z = 3 m to z = 3 m for the non-uniform charge distribution given to you by your TA.

  • Use the values of a = 0.5 m and N = 500. For this charge distribution describe how the fields are different from those of the uniformly charged ring.

Your program should be able to calculate the electric field components for a uniformly charged ring at any point P(x, y, z). If it doesn’t then modify it so that it can. As well, change your ringofcharge function to compute the electric field of a partial ring, i.e., a ring that only extends from = 0 to = 120 (a 1/3 ring).

  • Plot the three components Ex, Ey, and Ez, for a uniformly charged 1/3 ring of radius a = 0.5 m and = 2 mC/m at the point (0.75, 0.75, z) m, for z = 3 m and z = 3 m.

  • From these results, what is one observation that demonstrates that your calculations are probably correct?

  • If you placed an electron at the point (1, 1, 0), what would be the direction and magnitude of the resulting force on the electron due to this charged 1/3 ring?