Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Please help me fix an error

Im getting an error in python, "File "Untitled", line 17 s.velocity = s.velocity +((1.6e-22)cos(wt)*dt) ValueError: operands could not be broadcast together with shapes (3) (0) "

The code is posted below. does anybody know how i can fix this?

B = vector(0,0,0.5e-4) # Tesla, the earth's magnetic field

q = -1.6e-19 # Coulomb, the charge on an electron

m = .00507 # kg, the mass of an electron

s = sphere(radius=2.0e-6)

s.velocity = vector(100,0,0) # m/s

w=(2*pi,0,0)

trail=curve(color=color.blue,pos=s.pos)

s.pos=(0,0,0)

t=0

dt=1e-10 # s

while t < 3e-6:

if s.pos.x < 1e-6:

    s.velocity = s.velocity +((1.6e-22)*cos(w*t)*dt)

    trail.append(s.pos)

    t = t+dt

    rate(4e-7/dt)

else:
    s.acceleration = q*cross(s.velocity,B)/m
    s.velocity = s.velocity + s.acceleration*dt
    s.pos = s.pos + s.velocity*dt
    trail.append(s.pos)
    t = t+dt
    rate(4e-7/dt)
click to hide/show revision 2
No.2 Revision

Please help me fix an error

Im I'm getting an error in python, python:

"File "Untitled", line 17
    s.velocity = s.velocity +((1.6e-22)cos(wt)*dt)
+((1.6e-22)*cos(w*t)*dt)
ValueError: operands could not be broadcast together with shapes (3) (0) "

"

The code is posted below. does anybody know how i can fix this?this?:

B = vector(0,0,0.5e-4) # Tesla, the earth's magnetic field

field q = -1.6e-19 # Coulomb, the charge on an electron

electron m = .00507 # kg, the mass of an electron

electron s = sphere(radius=2.0e-6)

sphere(radius=2.0e-6) s.velocity = vector(100,0,0) # m/s

w=(2*pi,0,0)

trail=curve(color=color.blue,pos=s.pos)

s.pos=(0,0,0)

t=0

m/s w=(2*pi,0,0) trail=curve(color=color.blue,pos=s.pos) s.pos=(0,0,0) t=0 dt=1e-10 # s

s while t < 3e-6:

3e-6:
    if s.pos.x < 1e-6:
      s.velocity = s.velocity +((1.6e-22)*cos(w*t)*dt)
      trail.append(s.pos)
      t = t+dt
      rate(4e-7/dt)
  else:
     s.acceleration = q*cross(s.velocity,B)/m
     s.velocity = s.velocity + s.acceleration*dt
     s.pos = s.pos + s.velocity*dt
     trail.append(s.pos)
     t = t+dt
     rate(4e-7/dt)