Skip to content

Commit a12f5ed

Browse files
committed
Refactor
1 parent 55b7dd8 commit a12f5ed

9 files changed

Lines changed: 60 additions & 60 deletions

differentiation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def dy_difference(h, y0, y1):
3434
hx = x[i + 1] - x[i]
3535
dy[i] = dy_difference(hx, y[i], y[i + 1])
3636

37-
return [dy]
37+
return dy
3838

3939

4040
def three_point(x, y):
@@ -72,7 +72,7 @@ def dy_end(h, y0, y1, y2):
7272
else:
7373
dy[i] = dy_mid(hx, y[i - 1], y[i + 1])
7474

75-
return [dy]
75+
return dy
7676

7777

7878
def five_point(x, y):
@@ -111,4 +111,4 @@ def dy_end(h, y0, y1, y2, y3, y4):
111111
else:
112112
dy[i] = dy_mid(hx, y[i - 2], y[i - 1], y[i + 1], y[i + 2])
113113

114-
return [dy]
114+
return dy

integration.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def simpson(f, a, b, n):
2828
sum_odd += f(x)
2929

3030
xi = h / 3 * (f(a) + 2 * sum_even + 4 * sum_odd + f(b))
31-
return [xi]
31+
return xi
3232

3333

3434
def trapezoidal(f, a, b, n):
@@ -52,7 +52,7 @@ def trapezoidal(f, a, b, n):
5252
sum_x += f(x)
5353

5454
xi = h / 2 * (f(a) + 2 * sum_x + f(b))
55-
return [xi]
55+
return xi
5656

5757

5858
def simpson_array(x, y):
@@ -81,7 +81,7 @@ def simpson_array(x, y):
8181
sum_odd += y[i]
8282

8383
xi = h / 3 * (y[0] + 2 * sum_even + 4 * sum_odd + y[n - 1])
84-
return [xi]
84+
return xi
8585

8686

8787
def trapezoidal_array(x, y):
@@ -106,7 +106,7 @@ def trapezoidal_array(x, y):
106106
sum_x += y[i]
107107

108108
xi = h / 2 * (y[0] + 2 * sum_x + y[n - 1])
109-
return [xi]
109+
return xi
110110

111111

112112
def romberg(f, a, b, n):
@@ -143,4 +143,4 @@ def romberg(f, a, b, n):
143143
r[i, k] = r[i, k - 1] + \
144144
(r[i, k - 1] - r[i - 1, k - 1]) / ((4**k) - 1)
145145

146-
return [float(r[n - 1, n - 1])]
146+
return float(r[n - 1, n - 1])

interpolation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def lagrange(x, y, x_int):
2424
p = p * (x_int - x[j]) / (x[i] - x[j])
2525
y_int = y_int + p
2626

27-
return [y_int]
27+
return y_int
2828

2929

3030
def newton(x, y, x_int):
@@ -51,7 +51,7 @@ def newton(x, y, x_int):
5151
for i in range(m - 2, -1, -1):
5252
y_int = y_int * (x_int - x[i]) + del_y[i]
5353

54-
return [y_int]
54+
return y_int
5555

5656

5757
def gregory_newton(x, y, x_int):
@@ -79,7 +79,7 @@ def gregory_newton(x, y, x_int):
7979
for i in range(m - 2, -1, -1):
8080
y_int = y_int * (u - i) / (i + 1) + del_y[i]
8181

82-
return [y_int]
82+
return y_int
8383

8484

8585
def neville(x, y, x_int):
@@ -106,4 +106,4 @@ def neville(x, y, x_int):
106106
(x_int - x[i]) * q[i - 1, j - 1]) / (x[i] - x[i - j])
107107

108108
y_int = q[n - 1, n - 1]
109-
return [y_int, q]
109+
return y_int, q

linear_systems.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def backward_substitution(upper, d):
3030
x[i] = b[i] / upper[i, i]
3131
b[0:i] = b[0:i] - upper[0:i, i] * x[i]
3232

33-
return [x]
33+
return x
3434

3535

3636
def forward_substitution(lower, c):
@@ -58,7 +58,7 @@ def forward_substitution(lower, c):
5858
x[i] = b[i] / lower[i, i]
5959
b[i + 1:n] = b[i + 1:n] - lower[i + 1:n, i] * x[i]
6060

61-
return [x]
61+
return x
6262

6363

6464
def gauss_elimination_pp(a, b):
@@ -110,4 +110,4 @@ def gauss_elimination_pp(a, b):
110110
if a[n - 1, n - 1] == 0:
111111
print("Info: No unique solution.")
112112

113-
return [a]
113+
return a

linear_systems_iterative.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def jacobi(a, b, x0, toler, iter_max):
3030
break
3131
x0 = x.copy()
3232

33-
return [x, i]
33+
return x, i
3434

3535

3636
def gauss_seidel(a, b, x0, toler, iter_max):
@@ -60,4 +60,4 @@ def gauss_seidel(a, b, x0, toler, iter_max):
6060
break
6161
x0 = x.copy()
6262

63-
return [x, i]
63+
return x, i

0 commit comments

Comments
 (0)