Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions physics/magnetic_flux.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
Magnetic flux (Φ) is a scalar quantity that measures the number of magnetic field lines (B)
that pass through a closed area (A). Furthermore, the magnetic flux depends on the angle
formed between the magnetic field and the normal line (N) in area A. Check out the formula
used to calculate this flux:
________________________________________________________________________________________
Magnetic flux (Φ) is a scalar quantity that measures the number of magnetic field
lines (B) that pass through a closed area (A). Furthermore, the magnetic flux depends
on the angle formed between the magnetic field and the normal line (N) in area A.
Check out the formula used to calculate this flux:
------------
| Φ = B.A.cos(θ) |
------------
Expand All @@ -15,8 +16,7 @@
(Description adapted from https://en.wikipedia.org/wiki/Ideal_gas_law )
"""

from math import cos, radians as deg_to_rad

from math import cos, radians

def check_args(magnetic_field: float, area: float, angle: float) -> None:
"""
Expand Down Expand Up @@ -50,8 +50,8 @@ def magnetic_flux(magnetic_field: float, area: float, angle: float) -> float:
"""
>>> magnetic_flux(50.0, 2, 0.0)
100.0
>>> magnetic_flux(1.5, 3.0, 60.0)
2.25
>>> magnetic_flux(50, 2, 60.0)
50.0
>>> magnetic_flux(0.5, 4.0, 90.0)
0.0
>>> magnetic_flux(1, 2.0, 180.0)
Expand All @@ -67,8 +67,8 @@ def magnetic_flux(magnetic_field: float, area: float, angle: float) -> float:
... ValueError: Invalid area. Should be a positive number.
"""
check_args(magnetic_field, area, angle)
radians = deg_to_rad(angle)
return magnetic_field * area * cos(radians)
rad = radians(angle)
return magnetic_field * area * cos(rad)


if __name__ == "__main__":
Expand Down