Skip to content

Commit 50ff1f7

Browse files
committed
Added comment
1 parent 678dedb commit 50ff1f7

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

maths/area_under_curve.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from collections.abc import Callable
88

9-
9+
# The trapezoidal rule is a numerical method to approximate the area under a curve
1010
def trapezoidal_area(
1111
fnc: Callable[[float], float],
1212
x_start: float,
@@ -33,17 +33,17 @@ def trapezoidal_area(
3333
>>> f"{trapezoidal_area(f, -4.0, 4.0, 10000):.4f}"
3434
'384.0000'
3535
"""
36-
x1 = x_start
36+
xone = x_start
3737
fx1 = fnc(x_start)
3838
area = 0.0
3939
for _ in range(steps):
4040
# Approximates small segments of curve as linear and solve
4141
# for trapezoidal area
42-
x2 = (x_end - x_start) / steps + x1
42+
x2 = (x_end - x_start) / steps + xone
4343
fx2 = fnc(x2)
44-
area += abs(fx2 + fx1) * (x2 - x1) / 2
44+
area += abs(fx2 + fx1) * (x2 - xone) / 2
4545
# Increment step
46-
x1 = x2
46+
xone = x2
4747
fx1 = fx2
4848
return area
4949

0 commit comments

Comments
 (0)