maths.area_under_curve

Approximates the area under the curve using the trapezoidal rule

Functions

f(x)

trapezoidal_area(→ float)

Treats curve as a collection of linear lines and sums the area of the

Module Contents

maths.area_under_curve.f(x)
maths.area_under_curve.trapezoidal_area(fnc: collections.abc.Callable[[float], float], x_start: float, x_end: float, steps: int = 100) float

Treats curve as a collection of linear lines and sums the area of the trapezium shape they form :param fnc: a function which defines a curve :param x_start: left end point to indicate the start of line segment :param x_end: right end point to indicate end of line segment :param steps: an accuracy gauge; more steps increases the accuracy :return: a float representing the length of the curve

>>> def f(x):
...    return 5
>>> f"{trapezoidal_area(f, 12.0, 14.0, 1000):.3f}"
'10.000'
>>> def f(x):
...    return 9*x**2
>>> f"{trapezoidal_area(f, -4.0, 0, 10000):.4f}"
'192.0000'
>>> f"{trapezoidal_area(f, -4.0, 4.0, 10000):.4f}"
'384.0000'