I've followed most of the directions for this code but I keep getting an error message
DIRECTIONS
Here you will write code to model the electric field due to a charge. Use the following skeleton code:
GlowScript 2.7 VPython
ke= # 1/(4 pi epsilon0) in N m^2/C^2
sf= #scalefactor to scale image length
chg1 = sphere( ) #define charge 1
q1= #charge of particle 1
r0= # position of the field point
#calculate E field due to chg1 at field point
r01= #vector from source charge to field pt using variables from
above
r01_arrow=arrow(pos=vector(), axis=, length=, color=)
r01_mag = # define magnitude of r01
r01_hat = # define unit vector for r01
#compute E field
E1=
Efield1=arrow(pos=, axis=, length=, color=)
print("E1 = ", E1, " N/C")
1. A particle with charge +3 nC is located at m. Create a red sphere called “chg1” at the appropriate location to represent the particle. Define the charge of the particle in your code as well as “q1”.
2. Consider an observation location = m. Call this position “r0” in your code. • • Define the vector “r01” in your code as the vector from the source charge to the field point. Make sure to use symbolic names such as “chg1.pos” and “r0”–don’t retype numbers. •
3. Create a green arrow to represent the vector from the source to observation location (i.e. field point). You may need to adjust the radius of your sphere to make both objects visible. In calculating make sure to use symbolic names such as “charge1.pos”–don’t retype numbers. Call this arrow “r01_arrow”. You will need attributes pos(of the tail), length (there a nice function called mag() that give the length of a vector), axis (which gives the direction of the arrow), and color.
4. Write additional code to calculate the electric field at the observation location. Note, you will want to define constants like ke=9e9 N m2/C2 at the beginning of the program.
I've done 1-3 and my code looks like this so far:
GlowScript 2.9 VPython
ke=9e9 # 1/(4 pi epsilon0) in N m^2/C^2
sf=5e-6 #scalefactor to scale image length
chg1 = sphere(pos=vec(-0.06,0.01,-0.02) radius=2
color=color.red) #define charge 1
q1=3e-9 #charge of particle 1
r0=vec(-0.04,0.03,0.02) # position of the field point
r1=vec(-0.06,0.01,-0.02)
#calculate E field due to chg1 at field point
r01=r0-chg1.pos #vector from source charge to field pt using
variables from above
r01_arrow=arrow(pos=vector(), axis=, length=, color=)
r01_mag = mag(r01) # define magnitude of r01
r01_hat = r01/mag(r01_mag) # define unit vector for r01
#compute E field
E1=(ke*q1/mag(r01)**2)*r01_hat
Efield1=arrow(pos=chg1.pos, axis=sf*E1, length=mag(), color=color.green)
print("E1 = ", E1, " N/C")
I keep getting this error message: Error: Unexpected token name «radius», expected punc «,»; line 6: q1=3e-9
You have to use commas inside the sphere function.
Modify the line to,
chg1 = sphere(pos=vec(-0.06,0.01,-0.02), radius=2,
color=color.red) #define charge 1
You can use the following code:
GlowScript 2.9 VPython
ke=9e9 # 1/(4 pi epsilon0) in N m^2/C^2
sf=5e-6 #scalefactor to scale image length
chg1 =
sphere(pos=vec(-0.06,0.01,-0.02),radius=2,color=color.red) #define
charge 1
q1=3e-9 #charge of particle 1
r0=vec(-0.04,0.03,0.02) # position of the field point
r1=vec(-0.06,0.01,-0.02)
#calculate E field due to chg1 at field point
r01=r0-chg1.pos #vector from source charge to field pt using
variables from above
r01_mag = mag(r01) # define magnitude of r01
r01_hat = r01/r01_mag # define unit vector for r01
r01_arrow=arrow(pos=r01,axis=vector(5,0,0), length=r01_mag,
color=color.green, shaftwidth=1)
#compute E field
E1=(ke*q1/mag(r01)**2)*r01_hat
print("E1 = ", E1, " N/C")
I've followed most of the directions for this code but I keep getting an error message...