Professor Mason
VPython Electric Potential
In class, we were asked to modify VPython's program from a regular and simple code to a more complicated loop code. This is how the new code looks like after we spent a lot of time coding it.
First, we had to make a formula for r1 and V1 in order to calculate the electric potential in charge 1, followed by r2, V2 and r3, V3 shown in the picture attached below; r1, r2, r3 are the radius from each charge to the smaller sphere (observation point) that would show up later on after we finished the loop (the observation points would encircle around the 3 charges). Next, we created a while loop for each equation of charges, followed by the domain, such as how many observation points would encircle the 3 main charges; we decided to make loop for 20 times circling around the 3 main charges until it gets to 2pi in order to stop.
After we finished the first loop for each charges, we had to create the second loop in order to calculate the sum of the total electric potential circling around the 3 main charges. However, when we attempted to create loop for the sum, we failed, and the code did not work as planned, which is shown as #rednote in the picture attached above. Therefore, we created another loop, which define x, y , w equal to 1 and put a while loop in order to calculate it manually by putting all the numbers shown in the output as a list. After we made a list of those outputs, we had to calculate the sum, so we used sum(variable). Then, we had to use float in order to calculate the remaining decimals. We also had to put break at the end of the loop in order to prevent the infinite loop.
This is how it looks after we run the module with that code:
The picture attached above shows what the outputs are for the coding we created. The 20 numbers listed are the numbers for V1, V2, V3 after calculating the loop of electric potential for 20 times. Then we also provided the total sum of those electric potential in each charges. Then, we also calculated the total sum of all electric potential, which we put at the very end of the output. The diagram would look like this in the picture shown below. The cyan colored spheres are the observation points encircling around the red, green, and blue colored spheres.
No comments:
Post a Comment