Skip to content

Added Coulomb_Law - #8714

Merged
tianyizheng02 merged 14 commits into
TheAlgorithms:masterfrom
gudlu1925:master
Sep 27, 2023
Merged

Added Coulomb_Law#8714
tianyizheng02 merged 14 commits into
TheAlgorithms:masterfrom
gudlu1925:master

Conversation

@gudlu1925

@gudlu1925gudlu1925 commented May 7, 2023

Copy link
Copy Markdown
Contributor

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-keeperalgorithms-keeperBot added the tests are failing Do not merge until tests pass label May 7, 2023
Comment threadphysics/coulomb_law.py Outdated
@@ -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
Copy Markdown
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

@tianyizheng02tianyizheng02 left a comment

Copy link
Copy Markdown
Contributor

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

Comment threadphysics/coulomb_law.py Outdated

Copy link
Copy Markdown
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 threadphysics/coulomb_law.py Outdated
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Charles-AugustindeCoulomb, aFrenchphysicistin1784, measuredtheforcebetweentwopointchargesandhecameupwith
thetheorythattheforceisinverselyproportionaltothesquareofthedistancebetweenthecharges.
Healsofoundthatthisforceisdirectlyproportionaltotheproductofcharges (magnitudesonly).

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

Comment threadphysics/coulomb_law.py Outdated

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

Copy link
Copy Markdown
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 threadphysics/coulomb_law.py Outdated
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Where,FistheElectrostaticforce,q1q2aretheintensityoftwochargesrespecticvely,
ristheradiusandkiscoulombsconstantanditsvalueis9×10^9Nm^2C^2.
whereFistheelectrostaticforce,q1andq2arethemagnitudesofthetwochargesrespectively,
ristheradiusandk=9×10^9Nm^2/C^2isCoulomb'sconstant.

Comment threadphysics/coulomb_law.py Outdated

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
Copy Markdown
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

Comment threadphysics/coulomb_law.py Outdated

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

Copy link
Copy Markdown
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-keeperalgorithms-keeperBot added the awaiting reviews This PR is ready to be reviewed label May 9, 2023
Comment threadphysics/coulombs_law.py Outdated
@@ -0,0 +1,37 @@
"""
The law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges

Copy link
Copy Markdown
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'

Comment threadphysics/coulombs_law.py Outdated
@@ -0,0 +1,37 @@
"""
The law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Thelawstatesthatthemagnitudeoftheelectrostaticforceofattractionorrepulsionbetweentwopointcharges
Coulomb'slawstatesthatthemagnitudeoftheelectrostaticforceofattractionorrepulsionbetweentwopointcharges

For clarity

Comment threadphysics/coulombs_law.py Outdated

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

F = k*q1*q2/ r^2

Copy link
Copy Markdown
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

Comment threadphysics/coulombs_law.py Outdated

F = k*q1*q2/ r^2

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
kisproportionalityconstantandequals1/4πε0.
kistheCoulombconstantandequals1/(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 threadphysics/coulombs_law.py Outdated
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
Copy Markdown
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
kisCoulomb'sconstantandequals1/(4π*ε0).
q1ischargeoffirstbody (C)
q2ischargeofsecondbody (C)
risdistancebetweentwochargedbodies (m)
"""
defcoulombs_law(q1: float, q2: float, radius: float) ->float:
"""
F=k*q1*q2/r^2
kisCoulomb'sconstantandequals=1/(4π*ε0).
"""
defcoulombs_law(q1: float, q2: float, radius: float) ->float:
"""
:paramfloatq1: chargeoffirstbody (C)
:paramfloatq2: chargeofsecondbody (C)
:paramfloatr: distancebetweenthetwobodies

@gudlu1925

Copy link
Copy Markdown
ContributorAuthor

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

staleBot commented Jun 18, 2023

Copy link
Copy Markdown

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.

@stalestaleBot added the stale Used to mark an issue or pull request stale. label Jun 18, 2023
Comment threadphysics/coulombs_law.py Outdated
@@ -0,0 +1,37 @@
"""
Coulombs law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Coulombslawstatesthatthemagnitudeoftheelectrostaticforceofattractionorrepulsionbetweentwopointcharges
Coulomb'slawstatesthatthemagnitudeoftheelectrostaticforceofattractionorrepulsionbetweentwopointcharges

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

@stalestaleBot removed stale Used to mark an issue or pull request stale. labels Aug 14, 2023
@algorithms-keeperalgorithms-keeperBot removed the tests are failing Do not merge until tests pass label Sep 27, 2023
@tianyizheng02
tianyizheng02 merged commit eace4ce into TheAlgorithms:masterSep 27, 2023
@algorithms-keeperalgorithms-keeperBot removed the awaiting reviews This PR is ready to be reviewed label Sep 27, 2023
@isidroasisidroas mentioned this pull request Jan 25, 2025
14 tasks
Sign up for freeto 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

@gudlu1925@chriso345@tianyizheng02@rohan472000