- numpy - matplotlib Physim

Coulomb's Law Grapher

In this section you will analyze the results you observed from running the Coulomb's Law Simulation by plotting the points of the electrostatic force versus the distance of the particles.

Below is a graph of a the electrostatic force simulation run at two particles charged to be 4 C and 5 C, and how much the electrostatic force changed as the distance between the particles increases. As you can see, the graph starts out with a high electrostatic force when the particles were close to each other, however as the particles moved farther away from each other, the electrostatic force started to become weaker.


If you would like to see the full code for plotting the electrostatic force and distance graph, click the Display Code button below:


# import required libraries import matplotlib.pyplot as plt import numpy as np def doafit(force, distance, order): # initialize layout fig, ax = plt.subplots(figsize = (9,9)) # add scatterplot ax.scatter(distance, force, s=60, alpha=0.7, edgecolors="k") params = np.polyfit(distance, force, deg=order) ta = np.array(distance) xseq = np.linspace(ta.min(), ta.max(), num=100) # plot regression line ff = 0. for i in range(len(params)): ff += params[i]*np.power(xseq,order- i) ax.plot(xseq, ff, color="k", lw=2.5) # axis and title plot labelling ax.set(xlabel="Distance", ylabel="Force", title="Coulomb's Law") ax.grid() return plt # distance and force inputs force = [7988.93e9, 2876.02e9, 1244.81e9, 719e9, 319.56e9, 179.75e9, 44.94e9, 19.97e9, 11.23e9, 7.19e9, 3.67e9, 1.25e9, 0.8e9, 0.55e9, 0.37e9, 0.29e9, 0.20e9, 0.15e9, 0.11e9, 0.10e9] distance = [0.15, 0.25, 0.38, 0.50, 0.75, 1, 2, 3, 4, 5, 7, 12, 15, 18, 22, 25, 30, 35, 40, 43] deg = 2 doafit(force, distance, deg)

Here is a code editor so that you can input your electrostatic force and distance data points based on your observations made using the Coulombs's Law simulation.


This is how the electrostatic force and distance inputs should look like:

force = [7988.93e9, 2876.02e9, 1244.81e9, 719e9, 319.56e9, 179.75e9, 44.94e9, 19.97e9, 11.23e9, 7.19e9, 3.67e9, 1.25e9, 0.8e9, 0.55e9, 0.37e9, 0.29e9, 0.20e9, 0.15e9, 0.11e9, 0.10e9]

distance = [0.15, 0.25, 0.38, 0.50, 0.75, 1, 2, 3, 4, 5, 7, 12, 15, 18, 22, 25, 30, 35, 40, 43]

order = 1 means linear fit (i.e. polynomial of degree 1)

order = 2 means quadratic fit (i.e. polynomial of degree 2)

doafit is what generates a fit line or curve based on the time and height inputs.


In the electrostatic force simulation, graph the force and distance. What do you notice in the shape of the curve? is it linear? parabolic?

Do you notice any similarites or differences in your graph compared with the graph above?

Record your observations in the Coulomb's Law worksheet provided in the worksheet section of the Exercises Page.


force = [] distance = [] deg = 2 doafit(force, distance, deg)


Go Back to Force Exercises Page