What could be wrong with my charge motion model in Python?

  • Context: Python 
  • Thread starter Thread starter groom_03
  • Start date Start date
  • Tags Tags
    Work
Click For Summary
SUMMARY

The discussion centers on modeling the motion of a charge in Python, specifically how to calculate the acceleration of a moving charge influenced by a stationary charge using Coulomb's law. The user is attempting to implement a simulation using the Visual module but is encountering issues with the force calculation and updating the position of the moving charge. Key problems identified include the need to define the force variable before using it in the acceleration calculation and ensuring that the distance between the charges is updated correctly during the simulation loop.

PREREQUISITES
  • Understanding of Coulomb's law and electric force calculations
  • Familiarity with Python programming, specifically using the Visual module
  • Knowledge of basic physics concepts such as mass, acceleration, and motion
  • Experience with debugging techniques in Python, including the use of print statements
NEXT STEPS
  • Learn how to correctly implement force calculations in Python simulations
  • Research the Visual module for Python to understand its capabilities and limitations
  • Explore concepts of numerical integration for simulating motion over time
  • Investigate debugging strategies for Python code to identify and fix errors effectively
USEFUL FOR

Physics students, Python programmers, and anyone interested in simulating electric charge interactions and motion dynamics.

groom_03
Messages
1
Reaction score
0
Hi, I've got to model how a charge will move away from a stationary charge in python, i need the acceleration to be recalculated based on the force between the charges because the moving charge will decelerate, I've been up all night trying to get this to work but i just cannot figure out what's wrong

Code:
#Problem 4a
from visual import*

#mass is assumed to be proton rest mass

k=8.987551787362e09 #coulomb constant

#particle data

#Stationary particle
alpha=sphere(pos=(0,0,0), radius=0.01,color=color.blue)
qa=0.02
m=1.67262158e-27

#Moving particle
beta=sphere(pos=(1e-03,0,0), radius=0.01, color=color.red)
#particle seperations have been magnified by 1000
qb=0.02

#particle separation
dist=beta.pos-alpha.pos

a=f/m

#Lets make it move
while beta.pos.x>15e-03: #the moving particle will have moved 15mm
    rate(20000)
    dt=0.1
    f=(k*qa*qb)/dist**2
    beta.velocity=vector(1,0,0)
    #beta.velocity=a*dt
    betadelta_s=beta.velocity
    beta.pos=beta.pos+betadelta_s
    print a
    print f
    print beta.velocity

any help greatly appreciated

p.s i know nothing about computer programming
 
Technology news on Phys.org
What are some of the error messages that you're getting?
Also, use print statements at each stage to check that the values seem sane.

Also, far as I can tell you don't define f for
Code:
a=f/m
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
10K
  • · Replies 13 ·
Replies
13
Views
7K
  • · Replies 3 ·
Replies
3
Views
3K