1+ """
2+ According to Faraday's law, the emergence of electric currents depends on the change in
3+ magnetic flux. Therefore, we write that the time variation of the magnetic flux is
4+ equivalent to an electric potential measured in volts (V), which, for historical
5+ reasons, is called the induced electromotive force (ε). This relationship is expressed
6+ by the following formula:
7+
8+ ---------------
9+ | ε = ΔΦ / Δt |
10+ ---------------
11+
12+ ε --> induced electromotive force (V - volts)
13+
14+ ΔΦ = ΦF - Φi - variation in magnetic flux (Wb)
15+
16+ Δt - time interval (s)
17+
18+ Furthermore, due to the principle of conservation of energy, we need to add a negative
19+ sign to Faraday's law. This signal was introduced by Lenz's Law, which allows us to
20+ determine the direction of the electric current:
21+
22+ An electric current will always be formed in a direction such that the magnetic flux it
23+ produces opposes the magnetic flux that induced it.
24+
25+ The combination of these pieces of information gives rise to the Faraday-Lenz Law.
26+ Check it out:
27+
28+ -----------------
29+ | ε = - ΔΦ / Δt |
30+ -----------------
31+
32+ (Description adapted from https://en.wikipedia.org/wiki/Faraday%27s_law_of_induction )
33+ """
34+
35+
36+ def __check_args (final_flux : float , initinal_flux : float , time_interval : float ) -> None :
37+ """
38+ Check that the arguments are valid
39+ >>> __check_args(50, 10, -10)
40+ Traceback (most recent call last):
41+ ...
42+ ValueError: Invalid time interval. Should be a positive number.
43+ >>> __check_args("50", 10, 10)
44+ Traceback (most recent call last):
45+ ...
46+ TypeError: Invalid final flux. Should be an integer or float.
47+ """
48+
49+ # Ensure valid instance
50+ if not isinstance (final_flux , (int , float )):
51+ raise TypeError ("Invalid final flux. Should be an integer or float." )
52+
53+ if not isinstance (initinal_flux , (int , float )):
54+ raise TypeError ("Invalid final flux. Should be an integer or float." )
55+
56+ if not isinstance (time_interval , (int , float )):
57+ raise TypeError ("Invalid time interval. Should be an integer or float." )
58+
59+ # Ensure valid time interval
60+ if time_interval < 0 :
61+ raise ValueError ("Invalid time interval. Should be a positive number." )
62+
63+
64+ def induced_electromotive_force (
65+ final_flux : float , initinal_flux : float , time_interval : float
66+ ) -> float :
67+ """
68+ >>> induced_electromotive_force(50.0, 20, 3.0)
69+ -10.0
70+ >>> induced_electromotive_force(40, 30, 10.0)
71+ -1.0
72+ >>> induced_electromotive_force(30.0, 50.0, 10)
73+ 2.0
74+ >>> induced_electromotive_force(100, 100.0, 20.0)
75+ -0.0
76+ >>> induced_electromotive_force(10.0, 2.0, -2.0)
77+ Traceback (most recent call last):
78+ ...
79+ ValueError: Invalid time interval. Should be a positive number.
80+ >>> induced_electromotive_force(11.0, 'a', 5.0)
81+ Traceback (most recent call last):
82+ ...
83+ TypeError: Invalid final flux. Should be an integer or float.
84+ """
85+ __check_args (final_flux , initinal_flux , time_interval )
86+ flux_variation = final_flux - initinal_flux
87+ return round (- flux_variation / time_interval , 1 )
88+
89+
90+ if __name__ == "__main__" :
91+ from doctest import testmod
92+
93+ testmod ()
0 commit comments