Skip to content

Commit 6bf078b

Browse files
committed
Better 'docstrings'
1 parent 5bc6160 commit 6bf078b

8 files changed

Lines changed: 151 additions & 150 deletions

differentiation.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ def derivative_backward_difference(x, y):
99
All values in 'x' must be equally spaced.
1010
1111
Args:
12-
x: an array containing x values.
13-
y: an array containing y values.
12+
x (numpy.ndarray): x values.
13+
y (numpy.ndarray): y values.
1414
1515
Returns:
16-
dy: an array containing the first derivative values.
16+
dy (numpy.ndarray): the first derivative values.
1717
"""
1818
if x.size < 2 or y.size < 2:
1919
raise ValueError("'x' and 'y' arrays must have 2 values or more.")
@@ -43,11 +43,11 @@ def derivative_three_point(x, y):
4343
All values in 'x' must be equally spaced.
4444
4545
Args:
46-
x: an array containing x values.
47-
y: an array containing y values.
46+
x (numpy.ndarray): x values.
47+
y (numpy.ndarray): y values.
4848
4949
Returns:
50-
dy: an array containing the first derivative values.
50+
dy (numpy.ndarray): the first derivative values.
5151
"""
5252
if x.size < 3 or y.size < 3:
5353
raise ValueError("'x' and 'y' arrays must have 3 values or more.")
@@ -81,11 +81,11 @@ def derivative_five_point(x, y):
8181
All values in 'x' must be equally spaced.
8282
8383
Args:
84-
x: an array containing x values.
85-
y: an array containing y values.
84+
x (numpy.ndarray): x values.
85+
y (numpy.ndarray): y values.
8686
8787
Returns:
88-
dy: an array containing the first derivative values.
88+
dy (numpy.ndarray): the first derivative values.
8989
"""
9090
if x.size < 6 or y.size < 6:
9191
raise ValueError("'x' and 'y' arrays must have 6 values or more.")

integration.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ def composite_simpson(f, b, a, n):
55
"""Calculate the integral from 1/3 Simpson's Rule.
66
77
Args:
8-
f: function f(x).
9-
a: the initial point.
10-
b: the final point.
11-
n: number of intervals.
8+
f (function): the equation f(x).
9+
a (float): the initial point.
10+
b (float): the final point.
11+
n (int): number of intervals.
1212
1313
Returns:
14-
xi: integral value.
14+
xi (float): integral value.
1515
"""
1616
h = (b - a) / n
1717

@@ -33,13 +33,13 @@ def composite_trapezoidal(f, b, a, n):
3333
"""Calculate the integral from the Trapezoidal Rule.
3434
3535
Args:
36-
f: function f(x).
37-
a: the initial point.
38-
b: the final point.
39-
n: number of intervals.
36+
f (function): the equation f(x).
37+
a (float): the initial point.
38+
b (float): the final point.
39+
n (int): number of intervals.
4040
4141
Returns:
42-
xi: integral value.
42+
xi (float): integral value.
4343
"""
4444
h = (b - a) / n
4545

@@ -57,11 +57,11 @@ def composite_simpson_array(x, y):
5757
"""Calculate the integral from 1/3 Simpson's Rule.
5858
5959
Args:
60-
x: an array containing x values.
61-
y: an array containing y values.
60+
x (numpy.ndarray): x values.
61+
y (numpy.ndarray): y values.
6262
6363
Returns:
64-
xi: integral value.
64+
xi (float): integral value.
6565
"""
6666
if y.size != y.size:
6767
raise ValueError("'x' and 'y' must have same size.")
@@ -86,11 +86,11 @@ def composite_trapezoidal_array(x, y):
8686
"""Calculate the integral from the Trapezoidal Rule.
8787
8888
Args:
89-
x: an array containing x values.
90-
y: an array containing y values.
89+
x (numpy.ndarray): x values.
90+
y (numpy.ndarray): y values.
9191
9292
Returns:
93-
xi: integral value.
93+
xi (float): integral value.
9494
"""
9595
if y.size != y.size:
9696
raise ValueError("'x' and 'y' must have same size.")

interpolation.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ def lagrange(x, y, x_int):
77
"""Interpolates a value using the 'Lagrange polynomial'.
88
99
Args:
10-
x: an array containing x values.
11-
y: an array containing y values.
12-
x_int: value to interpolate.
10+
x (numpy.ndarray): x values.
11+
y (numpy.ndarray): y values.
12+
x_int (float): value to interpolate.
1313
1414
Returns:
15-
y_int: interpolated value.
15+
y_int (float): interpolated value.
1616
"""
1717
m = x.size
1818
y_int = 0
@@ -31,13 +31,13 @@ def neville(x, y, x_int):
3131
"""Interpolates a value using the 'Neville polynomial'.
3232
3333
Args:
34-
x: an array containing x values.
35-
y: an array containing y values.
36-
x_int: value to interpolate.
34+
x (numpy.ndarray): x values.
35+
y (numpy.ndarray): y values.
36+
x_int (float): value to interpolate.
3737
3838
Returns:
39-
y_int: interpolated value.
40-
q: coefficients matrix.
39+
y_int (float): interpolated value.
40+
q (numpy.ndarray): coefficients matrix.
4141
"""
4242
n = x.size
4343
q = np.zeros((n, n - 1))

linear_systems.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ def backward_substitution(upper, d):
99
"""Solve the upper linear system ux=d.
1010
1111
Args:
12-
upper: upper triangular matrix.
13-
d: an array containing d values.
12+
upper (numpy.ndarray): upper triangular matrix.
13+
d (numpy.ndarray): d values.
1414
1515
Returns:
16-
x: solution of linear the system.
16+
x (float): solution of linear the system.
1717
"""
1818
[n, m] = upper.shape
1919
b = d.astype(float)
@@ -37,11 +37,11 @@ def forward_substitution(lower, c):
3737
"""Solve the lower linear system lx=c.
3838
3939
Args:
40-
lower: lower triangular matrix.
41-
c: an array containing c values.
40+
lower (numpy.ndarray): lower triangular matrix.
41+
c (numpy.ndarray): c values.
4242
4343
Returns:
44-
x: solution of linear the system.
44+
x (float): solution of linear the system.
4545
"""
4646
[n, m] = lower.shape
4747
b = c.astype(float)
@@ -68,11 +68,11 @@ def gauss_elimination_pp(a, b):
6868
reduction).
6969
7070
Args:
71-
a: matrix A from system Ax=b.
72-
b: an array containing b values.
71+
a (numpy.ndarray): matrix A from system Ax=b.
72+
b (numpy.ndarray): b values.
7373
7474
Returns:
75-
a: augmented upper triangular matrix.
75+
a (numpy.ndarray): augmented upper triangular matrix.
7676
"""
7777
[n, m] = a.shape
7878

linear_systems_iterative.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ def jacobi(a, b, x0, toler, iter_max):
77
"""Jacobi method: solve Ax = b given an initial approximation x0.
88
99
Args:
10-
a: matrix A from system Ax=b.
11-
b: an array containing b values.
12-
x0: initial approximation of the solution.
13-
toler: tolerance (stopping criterion).
14-
iter_max: maximum number of iterations (stopping criterion).
10+
a (numpy.ndarray): matrix A from system Ax=b.
11+
b (numpy.ndarray): b values.
12+
x0 (numpy.ndarray): initial approximation of the solution.
13+
toler (float): tolerance (stopping criterion).
14+
iter_max (int): maximum number of iterations (stopping criterion).
1515
1616
Returns:
17-
x: solution of linear the system.
18-
iter: number of iterations used by the method.
17+
x (float): solution of linear the system.
18+
iter (int): number of iterations used by the method.
1919
"""
2020
# D and M matrices
2121
d = np.diag(np.diag(a))
@@ -37,15 +37,15 @@ def gauss_seidel(a, b, x0, toler, iter_max):
3737
"""Gauss-Seidel method: solve Ax = b given an initial approximation x0.
3838
3939
Args:
40-
a: matrix A from system Ax=b.
41-
b: an array containing b values.
42-
x0: initial approximation of the solution.
43-
toler: tolerance (stopping criterion).
44-
iter_max: maximum number of iterations (stopping criterion).
40+
a (numpy.ndarray): matrix A from system Ax=b.
41+
b (numpy.ndarray): b values.
42+
x0 (numpy.ndarray): initial approximation of the solution.
43+
toler (float): tolerance (stopping criterion).
44+
iter_max (int): maximum number of iterations (stopping criterion).
4545
4646
Returns:
47-
x: solution of linear the system.
48-
iter: number of iterations used by the method.
47+
x (float): solution of linear the system.
48+
iter (int): number of iterations used by the method.
4949
"""
5050
# L and U matrices
5151
lower = np.tril(a)

ode.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ def euler(f, a, b, n, ya):
99
Solve the IVP from the Euler method.
1010
1111
Args:
12-
f: function f(x).
13-
a: the initial point.
14-
b: the final point.
15-
n: number of intervals.
16-
ya: initial value.
12+
f (function): equation f(x).
13+
a (float): the initial point.
14+
b (float): the final point.
15+
n (int): number of intervals.
16+
ya (numpy.ndarray): initial values.
1717
1818
Returns:
19-
vx: an array containing x values.
20-
vy: an array containing y values (solution of IVP).
19+
vx (numpy.ndarray): x values.
20+
vy (numpy.ndarray): y values (solution of IVP).
2121
"""
2222
vx = np.zeros(n)
2323
vy = np.zeros(n)
@@ -50,16 +50,16 @@ def taylor2(f, df1, a, b, n, ya):
5050
Solve the IVP from the Taylor (Order Two) method.
5151
5252
Args:
53-
f: function f(x).
54-
df1: 1's derivative of function f(x).
55-
a: the initial point.
56-
b: the final point.
57-
n: number of intervals.
58-
ya: initial value.
53+
f (function): equation f(x).
54+
df1 (function): 1's derivative of equation f(x).
55+
a (float): the initial point.
56+
b (float): the final point.
57+
n (int): number of intervals.
58+
ya (numpy.ndarray): initial values.
5959
6060
Returns:
61-
vx: an array containing x values.
62-
vy: an array containing y values (solution of IVP).
61+
vx (numpy.ndarray): x values.
62+
vy (numpy.ndarray): y values (solution of IVP).
6363
"""
6464
vx = np.zeros(n)
6565
vy = np.zeros(n)
@@ -90,18 +90,18 @@ def taylor4(f, df1, df2, df3, a, b, n, ya):
9090
Solve the IVP from the Taylor (Order Four) method.
9191
9292
Args:
93-
f: function f(x).
94-
df1: 1's derivative of function f(x).
95-
df2: 2's derivative of function f(x).
96-
df3: 3's derivative of function f(x).
97-
a: the initial point.
98-
b: the final point.
99-
n: number of intervals.
100-
ya: initial value.
93+
f (function): equation f(x).
94+
df1 (function): 1's derivative of equation f(x).
95+
df2 (function): 2's derivative of equation f(x).
96+
df3 (function): 3's derivative of equation f(x).
97+
a (float): the initial point.
98+
b (float): the final point.
99+
n (int): number of intervals.
100+
ya (numpy.ndarray): initial values.
101101
102102
Returns:
103-
vx: an array containing x values.
104-
vy: an array containing y values (solution of IVP).
103+
vx (numpy.ndarray): x values.
104+
vy (numpy.ndarray): y values (solution of IVP).
105105
"""
106106
vx = np.zeros(n)
107107
vy = np.zeros(n)
@@ -133,15 +133,15 @@ def rk4(f, a, b, n, ya):
133133
Solve the IVP from the Runge-Kutta (Order Four) method.
134134
135135
Args:
136-
f: function f(x).
137-
a: the initial point.
138-
b: the final point.
139-
n: number of intervals.
140-
ya: initial value.
136+
f (function): equation f(x).
137+
a (float): the initial point.
138+
b (float): the final point.
139+
n (int): number of intervals.
140+
ya (numpy.ndarray): initial values.
141141
142142
Returns:
143-
vx: an array containing x values.
144-
vy: an array containing y values (solution of IVP).
143+
vx (numpy.ndarray): x values.
144+
vy (numpy.ndarray): y values (solution of IVP).
145145
"""
146146
vx = np.zeros(n)
147147
vy = np.zeros(n)
@@ -179,15 +179,15 @@ def rk4_system(f, a, b, n, ya):
179179
Solve from Runge-Kutta (Order Four) method.
180180
181181
Args:
182-
f: an array of functions f(x).
183-
a: the initial point.
184-
b: the final point.
185-
n: number of intervals.
186-
ya: an array of initial values.
182+
f (numpy.ndarray): equations f(x).
183+
a (float): the initial point.
184+
b (float): the final point.
185+
n (int): number of intervals.
186+
ya (numpy.ndarray): initial values.
187187
188188
Returns:
189-
vx: an array containing x values.
190-
vy: an array containing y values (solution of IVP).
189+
vx (numpy.ndarray): x values.
190+
vy (numpy.ndarray): y values (solution of IVP).
191191
"""
192192
m = len(f)
193193

0 commit comments

Comments
 (0)