MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / malus_law

Function malus_law

physics/malus_law.py:40–74  ·  view source on GitHub ↗

>>> round(malus_law(10,45),2) 5.0 >>> round(malus_law(100,60),2) 25.0 >>> round(malus_law(50,150),2) 37.5 >>> round(malus_law(75,270),2) 0.0 >>> round(malus_law(10,-900),2) Traceback (most recent call last): ... ValueError: In Malus Law, the angle

(initial_intensity: float, angle: float)

Source from the content-addressed store, hash-verified

38
39
40def malus_law(initial_intensity: float, angle: float) -> float:
41 """
42 >>> round(malus_law(10,45),2)
43 5.0
44 >>> round(malus_law(100,60),2)
45 25.0
46 >>> round(malus_law(50,150),2)
47 37.5
48 >>> round(malus_law(75,270),2)
49 0.0
50 >>> round(malus_law(10,-900),2)
51 Traceback (most recent call last):
52 ...
53 ValueError: In Malus Law, the angle is in the range 0-360 degrees
54 >>> round(malus_law(10,900),2)
55 Traceback (most recent call last):
56 ...
57 ValueError: In Malus Law, the angle is in the range 0-360 degrees
58 >>> round(malus_law(-100,900),2)
59 Traceback (most recent call last):
60 ...
61 ValueError: The value of intensity cannot be negative
62 >>> round(malus_law(100,180),2)
63 100.0
64 >>> round(malus_law(100,360),2)
65 100.0
66 """
67
68 if initial_intensity < 0:
69 raise ValueError("The value of intensity cannot be negative")
70 # handling of negative values of initial intensity
71 if angle < 0 or angle > 360:
72 raise ValueError("In Malus Law, the angle is in the range 0-360 degrees")
73 # handling of values out of allowed range
74 return initial_intensity * (math.cos(math.radians(angle)) ** 2)
75
76
77if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected