Created
May 10, 2017 16:48
-
-
Save RodolfoFerro/43abdd14ce9e8ec17f29b3c79fd1d270 to your computer and use it in GitHub Desktop.
Graphical analysis for a particle's attraction to a wire. (Based on Kellogg's: Foundation Of Potential Theory, Ch.1-S.4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
# Set wire, plot lenght and p position: | |
p = 6 # P position, along x axis | |
l = 5 # Wire's length | |
wire = np.linspace(0, l, 2) # Wire's discretization | |
lmbd = 1 # Lamnbda value | |
# Plotting domain: | |
if p > l: | |
x = np.linspace(-1, p+1, p+2*100) | |
else: | |
x = np.linspace(-1, p+1, l+1*100) | |
# Force function evaluated on domain x: | |
Fx = -lmbd*l / (x*(x-l)) | |
# Plot figure: | |
fig = plt.figure() | |
ax = fig.add_subplot(111) | |
plt.title('Straight homogeneous segment') | |
# Auxiliar axis: | |
plt.axvline(x=l/2, ymin=-1000, ymax = 1000, linewidth=0.5, color='k') | |
plt.axvline(x=l, ymin=-1000, ymax = 1000, linewidth=0.5, color='k') | |
plt.axvline(x=0, ymin=-1000, ymax = 1000, linewidth=0.5, color='k') | |
plt.axhline(y=0, xmin=-1000, xmax = 1000, linewidth=0.5, color='k') | |
# Main plots (wire, function, p): | |
w_plot, = plt.plot(wire, wire*0, '-g', label="Wire", linewidth=2) | |
g_plot, = plt.plot(x, Fx, '-b', label="F(x)", linewidth=1) | |
p_plot, = plt.plot(p, 0, 'or', label="P") | |
plt.legend(handles=[w_plot, p_plot, g_plot]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment