예제 #1
0
# chargeclient.py
#-----------------------------------------------------------------------

import sys
import stdio
from charge import Charge

# Accept floats x and y as command-line arguments. Create two Charge
# objects with fixed position and electrical charge, and write to
# standard output the potential at (x, y) due to the two charges.

x = float(sys.argv[1])
y = float(sys.argv[2])
c1 = Charge(.51, .63, 21.3)
c2 = Charge(.13, .94, 81.9)
v1 = c1.potentialAt(x, y)
v2 = c2.potentialAt(x, y)
stdio.writef('potential at (%.2f, %.2f) due to\n', x, y)
stdio.writeln('  ' + str(c1) + ' and')
stdio.writeln('  ' + str(c2))
stdio.writef('is %.2e\n', v1+v2)

#-----------------------------------------------------------------------

# python chargeclient.py .2 .5
# potential at (0.20, 0.50) due to
#   21.3 at (0.51, 0.63) and
#   81.9 at (0.13, 0.94)
# is 2.22e+12

# python chargeclient.py .51 .94
예제 #2
0
cy = 0.5

# Construct four charges.
c1 = Charge(cx + w, cy, 1.0)
# east
c2 = Charge(cx, cy - w, 1.0)
# south
c3 = Charge(cx - w, cy, 1.0)
# west
c4 = Charge(cx, cy + w, 1.0)
# north

# Compute potentials at (.25, .5).
px = 0.25
py = 0.5
v1 = c1.potentialAt(px, py)
v2 = c2.potentialAt(px, py)
v3 = c3.potentialAt(px, py)
v4 = c4.potentialAt(px, py)

# Compute and output total potential.
total = v1 + v2 + v3 + v4
stdio.writeln('total potential = ' + str(total))

#-----------------------------------------------------------------------

# python fourchargeclient.py 100
# total potential = 359600561.88465726

# python fourchargeclient.py 500
# total potential = 71920004.4950031
예제 #3
0
from charge import Charge
import sys

w = eval(sys.argv[1])

c1 = Charge(0.5 - w, 0.5, 1)
c2 = Charge(0.5 + w, 0.5, 1)
c3 = Charge(0.5, 0.5 - w, 1)
c4 = Charge(0.5, 0.5 + w, 1)

v1 = c1.potentialAt(.25, .5)
v2 = c2.potentialAt(.25, .5)
v3 = c3.potentialAt(.25, .5)
v4 = c4.potentialAt(.25, .5)

print('{0:.2e}'.format(v1 + v2 + v3 + v4))
예제 #4
0
import sys
import stdio
from charge import Charge

x = float(sys.argv[1])
y = float(sys.argv[2])

c1 = Charge(.51, .63, 21.3)
c2 = Charge(.13, .84, 81.9)

v1 = c1.potentialAt(x, y)
v2 = c2.potentialAt(x, y)

stdio.writef('potential at (%.2f, %.2f) due to \n', x, y)
stdio.writeln(' ' + str(c1) + ' and')
stdio.writeln(' ' + str(c2))
stdio.writef('is %.2e\n', v1 + v2)