—-
Magnetic Field Deflection
In this activity you will be simulating the effect of a charged particle moving perpendicularly through a uniform magnetic field. The starter code assumes a positive particle moving to the right (+x direction) moving through a magnetic field oriented out of the screen (+z direction). Load the provided code (below) into your GlowScript workspace.
Run the code. The red particle passes straight through the region defining the magnetic field without deflection. Your task is to add to the existing code so that the program will simulate the motion of the particle as it experiences the effect of the magnetic force. Use the provided charge, mass, velocity, and field strength values as you add the necessary lines of code to accurately simulate the deflection effect.
Once the code is working properly, answer the following questions. Be sure to take note of the initial values for charge, mass, velocity, and field strength (assume standard SI units):
GlowScript 2.8 VPython scene.width = 824 scene.height = 568 #consider the charge to be positive and the magnetic field to be in the positive z direction--out of the screen. field = box(pos=vector(0,0,0), size=vector(200,200,10), axis=vector(1,0,0), color=color.white, opacity=0.3) charge = sphere(pos=vector(-150,90,0), radius=2, color=color.red, make_trail=True) qval = 2E-4 vcharge = vector(5,0,0) mass = 0.1 mom = mass*vcharge B = vector (0,0,30.0) dt = .1 while charge.pos.y > 0: rate(120) charge.pos = charge.pos + vcharge*dt
GlowScript 2.8 VPython scene.width = 824 scene.height = 568 #consider the charge to be positive and the magnetic field to be in the positive z direction--out of the screen. field = box(pos=vector(0,0,0), size=vector(200,200,10), axis=vector(1,0,0), color=color.white, opacity=0.3) charge = sphere(pos=vector(-150,90,0), radius=2, color=color.red, make_trail=True) qval = 2E-4 vcharge = vector(5,0,0) mass = 0.1 mom = mass*vcharge B = vector (0,0,30.0) dt = .1 while charge.pos.y > -150 and charge.pos.x >= -150: rate(120) if charge.pos.x < -100: charge.pos = charge.pos + vcharge*dt else: if charge.pos.x < 100 and charge.pos.y > -100: force = qval*cross(vcharge,B) mom = mom + force*dt charge.pos = charge.pos +mom/mass*dt vcharge = mom/mass else: charge.pos = charge.pos + vcharge*dt print(mag(vcharge))