Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
repository:charged_particles [2021/02/02 23:06]
porcaro1 [Activity Information]
repository:charged_particles [2021/02/02 23:11]
porcaro1 [Activity]
Line 32: Line 32:
 ===Code=== ===Code===
 <code Python [enable_line_numbers="​true"​]>​ <code Python [enable_line_numbers="​true"​]>​
 +GlowScript 2.7 VPython
 +#Created by Meagan Brasseur, Sofia Villanueva, and John Plough on August 9,2019
 +#Debugged by Dan Weller August 17,2019
 +#Code is still INCOMPLETE
 +
 +##Objects##
 +Charge1 = sphere(pos=vec(0,​0,​0),​ radius=0.1, color=color.cyan)
 +Charge2 = sphere(pos=vec(5,​0,​0),​ radius=0.1, color=color.cyan)
 +Tcharge = sphere(pos=vec(2.5,​2.5,​0),​ radius=0.05,​ color=color.red)
 +
 +#Coulombic charges of our spheres
 +
 +q1    = 6.0*10**(-19)
 +q2    = 6.0*10**(-19)
 +qt    = -1.6*10**(-19)
 +
 +##​Constants##​
 +k = 9*10**9
 +mTest = 9.11*10**(-31)
 +vTest = vec(0,0,0)
 +
 +## Create graphs to track force
 +Grph1 = graph(title='​Force (1) v Distance',​ xtitle='​Distance (m)', ytitle='​Force (N)', fast=False, ymin=-1.4E-28,​ ymax=-1.3E-28) #initialize our graphs.
 +F1Graph = gcurve(color=color.green,​ label='​Force of Charge 1 on Test Charge'​) #Make a graph for the force on the test charge with respect to distance from Charge1.
 +
 +Grph1 = graph(title='​Force (2) v Distance',​ xtitle='​Distance (m)', ytitle='​Force (N)', fast=False, ymin=1.4E-28,​ ymax=1.3E-28) #initialize our graphs.
 +F2Graph = gcurve(color=color.green,​ label='​Force of Charge 2 on Test Charge'​) #Make a graph for the force on the test charge with respect to distance from Charge2.
 +
 +#Set up time variables for while loop
 +t=0
 +dt=1*10**(-4)
 +tf=1
 +
 +#While loop to iterate over the time interval
 +
 +while t < tf:
 +    rate(100)
 +# Defines the rate at which the program runs #
 +
 +##Hint: For the following calculations,​ break them up into components!##​
 +
 +#Come up with an equation for the force on your test charge from Charge 1
 +
 +    F1tx = 
 +    ​
 +    if Tcharge.pos.x <= Charge1.pos.x : 
 +        F1tx = 
 +    ​
 +    F1ty = 
 +  ​
 +    if Tcharge.pos.y <= Charge1.pos.y : 
 +        F1ty = 
 +    ​
 +    F1tz = 
 +    ​
 +    if Tcharge.pos.z <= Charge1.pos.z : 
 +        F1tz = 
 +    ​
 +    F1t = vec(F1tx,​F1ty,​F1tz)
 +    ​
 +#    print("​F1t = ", mag(F1t))
 +
 +##Come up with an equation for the force on your test charge from Charge 2
 +
 +    F2tx = 
 +    ​
 +    if Tcharge.pos.x <= Charge2.pos.x : 
 +        F2tx = 
 +    ​
 +    F2ty = 
 +    ​
 +    Tcharge.pos.y <= Charge2.pos.y : 
 +        F2ty = 
 +    ​
 +    F2tz = 
 +    ​
 +    Tcharge.pos.z <= Charge2.pos.z : 
 +        F2tz = 
 +    ​
 +    F2t = vec(F2tx,​F2ty,​F2tz)
 +#
 +##Come up with an equation for the net force on your test charge from both charges
 +#
 +    Fnetx = 
 +    Fnety = 
 +    Fnetz = 
 +
 +    Fnet = 
 +
 +#Come up with an equation for the net acceleration of your test charge from both charges
 + 
 +    at = 
 +
 +    at = 
 +
 +#Update the position of the test charge using the equation you came up with for acceleration. ​
 +
 +    vTest = vTest + at*dt
 +
 +    Tcharge.pos = Tcharge.pos + vTest*dt ​
 +
 +
 +#Graph the Net Force on the Test charge with regards to position. ​
 +
 +    F1Graph.plot(mag(Tcharge.pos),​mag(F1t))
 +    F2Graph.plot(mag(Tcharge.pos),​mag(F2t))
 +
 +    t = t + dt
 +
 </​code>​ </​code>​
 ---- ----
  • repository/charged_particles.txt
  • Last modified: 2021/02/02 23:29
  • by porcaro1