-
Notifications
You must be signed in to change notification settings - Fork 1
/
Electric_Field_and_Electric_Potential_Graphs.py
223 lines (184 loc) · 6.1 KB
/
Electric_Field_and_Electric_Potential_Graphs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import matplotlib.pyplot as plt
from numpy import linspace
from scipy.optimize import minimize_scalar
#r=20
#q=30
choice=input('Sphere, concentric sphere, or shell (s/sc/hs)?')
if choice=="s":
choice1=input('Conductor or insulator (c/i)?')
if choice1=="c":
r=float(input('Enter a radius (m)'))
q=float(input('Enter a uniformly distributed charge Q (C)'))
#maxE=(9*(10**9))*q*(r**-2)
#maxV=(9*(10**9))*q*(r**-1)
def fn(x):
if (x <= r):
return 0
elif (x <= 7*r):
return (9*(10**9))*q*(x**-2)
xList = linspace(0, 9999, 5000)
yList = [fn(x) for x in xList]
def fn(v):
if (v <= r):
return (9*(10**9))*q*(r**-1)
if (v <= 7*r):
return (9*(10**9))*q*(v**-1)
vList = linspace(0, 9999, 5000)
zList = [fn(v) for v in vList]
if choice1=="i":
r=float(input('Enter a radius (m)'))
q=float(input('Enter a uniformly distributed charge Q (C)'))
def fn(x):
if (x <= r):
return (9*(10**9))*q*(x)*(r**-3)
if (x <= 7*r):
return (9*(10**9))*q*(x**-2)
xList = linspace(0, 9999, 5000)
yList = [fn(x) for x in xList]
def fn(v):
if (v <= r):
return ((9*(10**9))*q*(-v**2)*(0.5)*(r**-3))+(3*0.5*(9*(10**9))*q*(r**-1))
if (v <= 7*r):
return (9*(10**9))*q*(v**-1)
vList = linspace(0, 9999, 5000)
zList = [fn(v) for v in vList]
elif choice=="sc":
choice2=input('Inner shell (c/i)')
if choice2=="i":
ra=float(input('Enter a radius [a] (m)'))
qa=float(input('Enter a uniformly distributed charge Q (C)'))
rb=float(input('Enter a radius [b] (m)'))
rc=float(input('Enter a radius [c] (m)'))
qb=float(input('Enter a uniformly distributed charge Q (C)'))
choice3=input('Outer shell (c/i)')
if choice3=="c":
def fn(x):
if (x <= ra):
return (9*(10**9))*qa*x*(ra**-3)
if (x <= rb):
return (9*(10**9))*qa*(x**-2)
if (x <= rc):
return 0
if (x<= 3*rc):
return (9*(10**9))*(qa+qb)*(x**-2)
xList = linspace(0, 9999, 5000)
yList = [fn(x) for x in xList]
def fn(v):
if (v <= ra):
return ((9*(10**9))*qa*(-v**2)*(0.5)*(ra**-3))+(3*0.5*(9*(10**9))*qa*(ra**-1))
if (v <= rb):
return (9*(10**9))*qa*(v**-1)
if (v<=rc):
return (9*(10**9))*(qa+qb)*(rb**-1)
if (v <= 3*rc):
return (9*(10**9))*(qa+qb)*(v**-1) #not working
vList = linspace(0, 9999, 5000)
zList = [fn(v) for v in vList]
if choice2=="c":
ra=float(input('Enter a radius [a] (m)'))
qa=float(input('Enter a uniformly distributed charge Q (C)'))
rb=float(input('Enter a radius [b] (m)'))
rc=float(input('Enter a radius [c] (m)'))
qb=float(input('Enter a uniformly distributed charge Q (C)'))
choice3=input('Outer shell (c/i)')
if choice3=="c":
def fn(x):
if (x <= ra):
return 0
if (x <= rb):
return (9*(10**9))*qa*(x**-2)
if (x <= rc):
return 0
if (x<= 3*rc):
return (9*(10**9))*(qa+qb)*(x**-2)
xList = linspace(0, 9999, 5000)
yList = [fn(x) for x in xList]
def fn(v):
if (v <= ra):
return (9*(10**9))*qa*(ra**-1)
if (v <= rb):
return (9*(10**9))*qa*(v**-1)
if (v<=rc):
return (9*(10**9))*(qa)*(rb**-1)
if (v <= 3*rc):
return (9*(10**9))*(qa+qb)*(v**-1) #not working
vList = linspace(0, 9999, 5000)
zList = [fn(v) for v in vList]
if choice3=="i":
def fn(x):
if (x <= ra):
return 0
if (x <= rb):
return (9*(10**9))*qa*(x**-2)
if (x <= rc):
return ((9*(10**9))*qb*(x**3-rb**3)*((x**2)*(rc**3-rb**3)**-1))+(9*(10**9))*qa*(x**-2)
if (x <= 5*rc):
return ((9*(10**9))*(qb)*(x**-2)) #not working
xList = linspace(0, 9999, 5000)
yList = [fn(x) for x in xList]
def fn(v):
if (v <= ra):
return ((9*(10**9))*qa*(-v**2)*(0.5)*(ra**-3))+(3*0.5*(9*(10**9))*qa*(ra**-1))
if (v <= rb):
return (9*(10**9))*qa*(v**-1)
if (v<=rc):
return (9*(10**9))*(qa+qb)*(rb**-1)
if (v <= 3*rc):
return (9*(10**9))*(qa+qb)*(v**-1) #not working
elif choice=="hs":
choice1=input('Conductor or insulator (c/i)?')
if choice1=="c":
rin=float(input('Enter an inner radius (m)'))
rout=float(input('Enter an outer radius (m)'))
q=float(input('Enter a uniformly distributed charge Q (C)'))
def fn(x):
if (x <= rin):
return 0
if (x <= rout):
return 0
if (x <= 5*rout):
return (9*(10**9))*q*(x**-2)
xList = linspace(0, 9999, 5000)
yList = [fn(x) for x in xList]
def fn(v):
if (v <= rin):
return (9*(10**9))*q*(rin**-1)
if (v <= 5*rout):
return (9*(10**9))*q*(v**-1)
vList = linspace(0, 9999, 5000)
zList = [fn(v) for v in vList]
if choice1=="i":
rin=float(input('Enter an inner radius (m)'))
rout=float(input('Enter an outer radius (m)'))
q=float(input('Enter a uniformly distributed charge Q (C)'))
def fn(x):
if (x <= rin):
return 0
if (x<=rout):
return ((9*(10**9))*q*(x**3-rin**3)*(((x**2)*(rout**3-rin**3))**-1))
if (x <= 7*rout):
return (9*(10**9))*q*(x**-2)
xList = linspace(0, 9999, 5000)
yList = [fn(x) for x in xList]
def fn(v):
if (v <= rin):
return (9*(10**9))*q*(rin**-1)
if (v <= rout):
return -(9*(10**9))*q*((rout**3-rin**3)**-1)*(v**3+2*rin**3)*((2*v)**-1)+(9*(10**9))*q*(rout**-1)
if (v <= 7*rout):
return (9*(10**9))*q*(v**-1) #not working
vList = linspace(0, 9999, 5000)
zList = [fn(v) for v in vList]
plt.plot(xList, yList)
plt.xlabel("Distance from the Center (m)")
plt.ylabel("Electric Field (N/C)")
plt.title("Electric Field as a Function of Distance")
#plt.xlim(left=0)
plt.show()
plt.plot(vList, zList)
plt.xlabel("Distance from the Center (m)")
plt.ylabel("Electric Potential (V)")
#plt.xlim(left=0)
plt.title("Electric Potential as a Function of Distance")
plt.show()
#PRINT MAX VALUES AND EQUATIONS!!!