ubsuny / CP1-24-HW3

Homework 3 template for CP1-24
1 stars 16 forks source link

Electric Field of a Sphere #45

Closed abruns123 closed 6 days ago

abruns123 commented 1 week ago

The electricSphere module uses the getField function to produce the vector which defines the electric field of a spherical shell that may be defined by the user in terms of its center relative to the origin, its charge density, and radius. The user also determines the point at which the electric field is measured.

This is all tested by electricSphereTester.

The theory markdown file goes over how to determine the electric field of a sphere with constant volume charge density.

review-notebook-app[bot] commented 1 week ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

laserlab commented 1 week ago

@Cosmos491 please review asap

Cosmos491 commented 1 week ago

@laserlab I am on it, professor.

Cosmos491 commented 1 week ago

I will start from the beginning:

  1. The first code calculates the electric field produced by a charged sphere. If the point lies inside the sphere, the field magnitude is calculated using a smaller effective radius. The elecField function provides the direction and magnitude of the electric field at point p relative to the sphere center o.

  2. The second code is the unit test code for the electricSphere module.

  3. The explanation concludes with the fact that: Inside the sphere, the electric field has a linear relationship with r. Outside, the electric field has a decreasing parabolic relationship with r. It also mentions that the electric field is a vector quantity and that the derived equations describe the magnitude of the electric field in the radial direction from the center.

Below I will review them in the same manner:

  1. There is a potential issue with dividing by zero in getUVec(), when the magnitude is zero. So, I suggest adding error handling for potential division by zero in getUVec. Simplify the implementation of zeroCondition for better readability.

  2. Simplify and improve the readability of the test_behavior function by breaking down the logic into smaller parts. Replace floating-point equality checks with assert_allclose to prevent errors due to rounding.

  3. The phrase "sphereical shell" should be corrected to "spherical shell". Consider breaking down the explanation into smaller sections for clarity. But, overall the theory looks fine.

abruns123 commented 1 week ago

At this time, I have made adjustments according to your specifications.

laserlab commented 6 days ago

main loop is not for testing, merging anyway