Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Coulomb_Law #8714

Merged
merged 14 commits into from
Sep 27, 2023
Merged

Added Coulomb_Law #8714

merged 14 commits into from
Sep 27, 2023

Conversation

gudlu1925
Copy link
Contributor

@gudlu1925 gudlu1925 commented May 7, 2023

Describe your change:

I have added a Coulomb law python code under physics to calculate force between two charges.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label May 7, 2023
@@ -0,0 +1,63 @@
"""
Description : The law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges is directly proportional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ruff . then ruff . --fix to fix ruff and pre-commit issues

Copy link
Contributor

@tianyizheng02 tianyizheng02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that the header docstring is too verbose and some parts, such as the paragraph about Coulomb discovering the formula, are either a bit repetitive or not particularly important to include. Instead of directly quoting the cited article for most of the documentation, consider briefly summarizing what the formula calculates and discussing the intuition behind it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider changing the file name from coulomb_law.py to coulombs_law.py, since the name is "Coulomb's Law"

Comment on lines 12 to 14
Charles-Augustin de Coulomb, a French physicist in 1784, measured the force between two point charges and he came up with
the theory that the force is inversely proportional to the square of the distance between the charges.
He also found that this force is directly proportional to the product of charges (magnitudes only).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Charles-Augustin de Coulomb, a French physicist in 1784, measured the force between two point charges and he came up with
the theory that the force is inversely proportional to the square of the distance between the charges.
He also found that this force is directly proportional to the product of charges (magnitudes only).

The history of the formula isn't particularly important to understanding the formula itself, imo


def coulombs_law(q1: float, q2: float, radius: float) -> float:
"""
The Electrostatic Force formula is given as: (k*q1*q2)/(r**2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifying the units of q1, q2, radius, and the output would be helpful

Comment on lines 33 to 34
Where, F is the Electrostatic force,q1 q2 are the intensity of two charges respecticvely ,
r is the radius and k is coulombs constant and its value is 9×10^9 N⋅m^2⋅C^−2 .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Where, F is the Electrostatic force,q1 q2 are the intensity of two charges respecticvely ,
r is the radius and k is coulombs constant and its value is 9×10^9 Nm^2C^2 .
where F is the electrostatic force, q1 and q2 are the magnitudes of the two charges respectively,
r is the radius and k = 9×10^9 Nm^2/C^2 is Coulomb's constant.


where k is proportionality constant and equals to 1/4πε0.

Here, ε0 is the epsilon naught and it signifies permittivity of a vacuum. The value of k comes 9 × 10^9 Nm^2/ C^2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9 x 10^9 N * m^2 / C^2 is only an approximation for Coulomb's constant. Wikipedia gives a much more precise value of 8.9875517923 x 10^9 N * m^2 / C^2


if radius <= 0:
raise ValueError("The radius is always a positive non zero integer")
return ((9 * 10**9) * q1 * q2) / (radius**2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ((9 * 10**9) * q1 * q2) / (radius**2)
k = 8.9875517923 * 10**9
return (k * q1 * q2) / (radius**2)

Updated code with more precise value of Coulomb's constant

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label May 9, 2023
@@ -0,0 +1,37 @@
"""
The law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line no.2,3,5 should be break into multiple as it is long ....use 'ruff . --fix'

@@ -0,0 +1,37 @@
"""
The law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges
Coulomb's law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges

For clarity


Coulomb studied the repulsive force between bodies having electrical charges of the same sign.

F = k*q1*q2/ r^2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
F = k*q1*q2/ r^2
F = k*q1*q2/r^2

Spacing


F = k*q1*q2/ r^2

k is proportionality constant and equals 1/4πε0.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
k is proportionality constant and equals 1/4πε0.
k is the Coulomb constant and equals 1/(4π * ε0).

According to Wikipedia, $k$ is called the Coulomb constant

Added parentheses for clarity, because otherwise it looks like $\frac{1}{4} \pi \varepsilon_0$ and not $\frac{1}{4 \pi \varepsilon_0}$

Comment on lines 7 to 17
F = k*q1*q2/r^2

k is Coulomb's constant and equals 1/(4π*ε0).
q1 is charge of first body (C)
q2 is charge of second body (C)
r is distance between two charged bodies (m)
"""


def coulombs_law(q1: float, q2: float, radius: float) -> float:
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
F = k*q1*q2/r^2
k is Coulomb's constant and equals 1/(4π*ε0).
q1 is charge of first body (C)
q2 is charge of second body (C)
r is distance between two charged bodies (m)
"""
def coulombs_law(q1: float, q2: float, radius: float) -> float:
"""
F = k*q1*q2/r^2
k is Coulomb's constant and equals = 1/(4π*ε0).
"""
def coulombs_law(q1: float, q2: float, radius: float) -> float:
"""
:param float q1: charge of first body (C)
:param float q2: charge of second body (C)
:param float r: distance between the two bodies

@gudlu1925
Copy link
Contributor Author

Will you please guide me with ruff checking?
I have done ruff. and ruff. --fix is working fine in my system but still the same error is showing in here.

@stale
Copy link

stale bot commented Jun 18, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Used to mark an issue or pull request stale. label Jun 18, 2023
@@ -0,0 +1,37 @@
"""
Coulombs law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Coulombs law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges
Coulomb's law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges

Small grammar fix. Other than that, it looks good to go 👍

@stale stale bot removed stale Used to mark an issue or pull request stale. labels Aug 14, 2023
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Sep 27, 2023
@tianyizheng02 tianyizheng02 merged commit eace4ce into TheAlgorithms:master Sep 27, 2023
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Sep 27, 2023
sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Sep 15, 2024
* Create coulomb_law.py

* Update coulomb_law.py

* Update coulomb_law.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update and rename coulomb_law.py to coulombs_law.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update coulombs_law.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update coulombs_law.py

* Update coulombs_law.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update coulombs_law.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update coulombs_law.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants