Monday, May 4, 2015

4/18/15 - Python Projects

Over the weekend, Professor Mason had assigned VPython projects to the students. The project description is in the lecture notes and is based off the ones that we had worked on during class.


The first one we did in class, we found the electric potential at multiple observation points given two charges.


Here we have two point charges of equal magnitude and opposite signs, the observation points are equal distant from their respective point and we found that the electric potentials have the same magnitude but opposite signs.


This is the code that was used in class to produce the previous images, a for loop was implemented to cycle through a list of observation locations and print their respective electric potentials.


Here is the same code we has used in class, but rather than doing set observation locations from a list, a while loop was implemented. This allows the observation locations to move around the point charges in a circle. The electric field due to the point charges is calculated at each point and then printed to it's appropriate location.


A screenshot of the final product from the previous code.



This code is similar to the previous projects, but was completely rewritten. It starts off by making constants that will be used later on in the program.
Then observation locations are set a points given in the lecture notes, then variables to be used in the calculation of the electric field, and finally the labels that go along with them.
Two while loops sum up the total electric potential and update the label accordingly.  



A screenshot before the loop finishes.


The final output.


No comments:

Post a Comment