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
Previous revision
repository:charged_balloons [2020/03/24 02:15]
porcaro1 [Activity]
repository:charged_balloons [2021/03/24 23:40] (current)
porcaro1 [Answer Key]
Line 29: Line 29:
   * Model two charged balloons hanging from strings, incorporating the effects of gravity   * Model two charged balloons hanging from strings, incorporating the effects of gravity
 ===Code=== ===Code===
 +[[https://​www.glowscript.org/#/​user/​porcaro1/​folder/​RepositoryPrograms/​program/​ChargedBalloons-Incomplete/​edit | Link]]
 +<code Python [enable_line_numbers="​true"​]>​
 +GlowScript 2.7 VPython
 +
 +#​get_library('​https://​rawgit.com/​perlatmsu/​physutil/​master/​js/​physutil.js'​)
 +
 +#Define some things
 +k=9e9 #​electrostatic constant
 +t = 0 #time counter
 +dt = 0.00005 #time increment
 +
 +x1 = -5 #x location for charge 1
 +y1 = 0 #y location for charge 1
 +z1 = 0 #z location for charge 1
 +m1 = 9e-31 #mass or charge 1
 +
 +x2 = 5 #x location for charge 1
 +y2 = 0 #y location for charge 1
 +z2 = 0 #z location for charge 1
 +m2 = 9e-31 #mass or charge 2
 +
 +c1 = sphere(pos=vec(x1,​y1,​z1),​ color = vec(1,0,0)) #create charged particle 1
 +c2 = sphere(pos=vec(x2,​y2,​z2),​ color = vec(0,1,0)) #create charged particle 2
 +
 +r12 = c1.pos-c2.pos #​distance ​ between charge 1 and charge 2
 +
 +c1.charge = 1.6e-19 #charge on charge 1 - note the sign of the charge
 +c1.vel = vec(0,0,0) #initial velocity of charge 1
 +c1.accel = vec(0,0,0) #initial acceleration of charge 1
 +
 +c2.charge = -1.6e-19 #charge on charge 2 - note the sign of the charge
 +c2.vel = vec(0,0,0) #initial velocity of charge 2
 +c2.accel = vec(0,0,0) #initial acceleration of charge 2
 +
 +#loop to move charged objects
 +while mag(r12) = 0:
 +   ​rate(1000)
 +   
 +   ​c1.eforcec2 =       #​electrostatic force of charge 2 on charge 1
 +   ​c2.eforcec1 =       #​electrostatic force of charge 1 on charge 2
 +  ​
 +   #add electrostatic force arrow to charges
 +   ​attach_arrow (c1, "​eforcec2",​ shaftwidth = .2, scale = 1e30, color = vector (1,0,0))
 +   ​attach_arrow (c2, "​eforcec1",​ shaftwidth = .2, scale = 1e30, color = vector (0,1,0))
 +   
 +   ​c1.accel =          #​acceleration of charge 1
 +   ​c2.accel =          #​acceleration of charge 2
 +    ​
 +   ​c1.vel =            #new velocity of charge 1
 +   ​c2.vel =            #new velocity of charge 2
 +   
 +   ​c1.pos =            #new position of charge 1
 +   ​c2.pos =            #new position of charge 2
 +  ​
 +   r12 =               #new distance between charge 1 and charge 2
 + 
 +   ​t=t+dt #increment time variable </​code>​
  
 ====Answer Key=== ====Answer Key===
 ===Handout=== ===Handout===
 +See highlighted code for notable changes to the program. The appropriate range of charge magnitudes should be in the nanocoulombs.
 +
 ===Code=== ===Code===
 +[[https://​www.glowscript.org/#/​user/​porcaro1/​folder/​RepositoryPrograms/​program/​ChargedBalloons-Solution | Link]]
 +<code Python [enable_line_numbers="​true",​ highlight_lines_extra="​36,​37,​43,​44,​46,​47,​49,​50,​52"​]>​
 +GlowScript 2.7 VPython
 +
 +#​get_library('​https://​rawgit.com/​perlatmsu/​physutil/​master/​js/​physutil.js'​)
 +
 +#Define some things
 +k=9e9 #​electrostatic constant
 +t = 0 #time counter
 +dt = 0.00005 #time increment
 +
 +x1 = -5 #x location for charge 1
 +y1 = 0 #y location for charge 1
 +z1 = 0 #z location for charge 1
 +m1 = 9e-31 #mass or charge 1
 +
 +x2 = 5 #x location for charge 1
 +y2 = 0 #y location for charge 1
 +z2 = 0 #z location for charge 1
 +m2 = 9e-31 #mass or charge 2
 +
 +c1 = sphere(pos=vec(x1,​y1,​z1),​ color = vec(1,0,0)) #create charged particle 1
 +c2 = sphere(pos=vec(x2,​y2,​z2),​ color = vec(0,1,0)) #create charged particle 2
 +
 +r12 = c1.pos-c2.pos #​distance ​ between charge 1 and charge 2
 +
 +c1.charge = 1.6e-19 #charge on charge 1 - note the sign of the charge
 +c1.vel = vec(0,0,0) #initial velocity of charge 1
 +c1.accel = vec(0,0,0) #initial acceleration of charge 1
 +
 +c2.charge = -1.6e-19 #charge on charge 2 - note the sign of the charge
 +c2.vel = vec(0,0,0) #initial velocity of charge 2
 +c2.accel = vec(0,0,0) #initial acceleration of charge 2
  
 +#loop to move charged objects
 +while mag(r12) >= 2:
 +   ​rate(1000)
 +   ​c1.eforcec2 = (k*c1.charge*c2.charge*r12)/​(mag(r12)**3) #​electrostatic force of charge 2 on charge 1
 +   ​c2.eforcec1 = -c1.eforcec2 #​electrostatic force of charge 1 on charge 2
 +  ​
 +    #add electrostatic force arrow to charges
 +   ​attach_arrow (c1, "​eforcec2",​ shaftwidth = .2, scale = 1e30, color = vector (1,0,0))
 +   ​attach_arrow (c2, "​eforcec1",​ shaftwidth = .2, scale = 1e30, color = vector (0,1,0))
 +   
 +   ​c1.accel = (c1.eforcec2/​m1) #​acceleration of charge 1
 +   ​c2.accel = (c2.eforcec1/​m2) #​acceleration of charge 2
 +    ​
 +   ​c1.vel = c1.accel*t #new velocity of charge 1
 +   ​c2.vel = c2.accel*t #new velocity of charge 2
 +   
 +   ​c1.pos = c1.pos+(c1.vel*t) #new position of charge 1
 +   ​c2.pos = c2.pos+(c2.vel*t) #new position of charge 2
 +  ​
 +   r12 = c1.pos - c2.pos #new distance between charge 1 and charge 2
 + 
 +   ​t=t+dt #increment time variable </​code>​
 ---- ----
 ====See Also==== ====See Also====
  • repository/charged_balloons.1585016141.txt.gz
  • Last modified: 2020/03/24 02:15
  • by porcaro1