Skip to content

Commit c62cc61

Browse files
github-actionsgithub-actions
github-actions
authored and
github-actions
committed
fixup! Format Python code with psf/black push
1 parent e25d424 commit c62cc61

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

maths/line_length.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from typing import Callable, Union
22
import math as m
33

4-
def line_length(fnc: Callable[[Union[int, float]], Union[int, float]],
5-
x_start: Union[int, float],
6-
x_end: Union[int, float],
7-
steps: int = 100) -> float:
4+
5+
def line_length(
6+
fnc: Callable[[Union[int, float]], Union[int, float]],
7+
x_start: Union[int, float],
8+
x_end: Union[int, float],
9+
steps: int = 100,
10+
) -> float:
811

912
"""
1013
Approximates the arc length of a line segment by treating the curve as a
@@ -48,10 +51,11 @@ def line_length(fnc: Callable[[Union[int, float]], Union[int, float]],
4851

4952
return length
5053

54+
5155
if __name__ == "__main__":
5256

5357
def f(x):
54-
return m.sin(10*x)
58+
return m.sin(10 * x)
5559

5660
print("f(x) = sin(10 * x)")
5761
print("The length of the curve from x = -10 to x = 10 is:")

maths/numerical_integration.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
from typing import Callable, Union
66

7-
def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
8-
x_start: Union[int, float],
9-
x_end: Union[int, float],
10-
steps: int = 100) -> float:
7+
8+
def trapezoidal_area(
9+
fnc: Callable[[Union[int, float]], Union[int, float]],
10+
x_start: Union[int, float],
11+
x_end: Union[int, float],
12+
steps: int = 100,
13+
) -> float:
1114

1215
"""
1316
Treats curve as a collection of linear lines and sums the area of the
@@ -39,9 +42,9 @@ def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
3942

4043
# Approximates small segments of curve as linear and solve
4144
# for trapezoidal area
42-
x2 = (x_end - x_start)/steps + x1
45+
x2 = (x_end - x_start) / steps + x1
4346
fx2 = fnc(x2)
44-
area += abs(fx2 + fx1) * (x2 - x1)/2
47+
area += abs(fx2 + fx1) * (x2 - x1) / 2
4548

4649
# Increment step
4750
x1 = x2
@@ -52,12 +55,12 @@ def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
5255
if __name__ == "__main__":
5356

5457
def f(x):
55-
return x**3
58+
return x ** 3
5659

5760
print("f(x) = x^3")
5861
print("The area between the curve, x = -10, x = 10 and the x axis is:")
5962
i = 10
6063
while i <= 100000:
6164
area = trapezoidal_area(f, -5, 5, i)
6265
print("with {} steps: {}".format(i, area))
63-
i*=10
66+
i *= 10

0 commit comments

Comments
 (0)