executable-engineering 0.1.52__py3-none-any.whl → 0.1.53__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -72,7 +72,6 @@ from .differentiation_module import (
72
72
  plot_uneven_spacing_derivative,
73
73
  )
74
74
  from .integration_module import (
75
- trapezoid_rule,
76
75
  simpson_13_rule,
77
76
  simpson_38_rule,
78
77
  romberg_integration,
@@ -181,7 +180,6 @@ __all__ = [
181
180
  "plot_frequency_noise_spectrum",
182
181
  "plot_uneven_spacing_derivative",
183
182
  # Integration module
184
- "trapezoid_rule",
185
183
  "simpson_13_rule",
186
184
  "simpson_38_rule",
187
185
  "romberg_integration",
@@ -1,14 +1,16 @@
1
1
  import numpy as np
2
2
  import plotly.graph_objects as go
3
3
 
4
- def left_riemann(f, a, b, h):
5
- x_left = np.arange(a, b, h)
4
+ def left_riemann(f, a, b, n):
5
+ h = (b - a) / n
6
+ x_left = np.linspace(a, b - h, n)
6
7
  y_left = f(x_left)
7
8
  integral_approx = np.sum(y_left * h)
8
9
 
9
10
  return {
10
11
  "x_left": x_left,
11
12
  "y_left": y_left,
13
+ "n": n,
12
14
  "integral_approx": integral_approx,
13
15
  "a": a,
14
16
  "b": b,
@@ -132,9 +134,9 @@ def visualize_left_riemann(f, data):
132
134
  return fig
133
135
 
134
136
 
135
- def right_riemann(f, a, b, h):
136
- x_right = np.arange(a + h, b + h, h)
137
- x_right = x_right[x_right <= b]
137
+ def right_riemann(f, a, b, n):
138
+ h = (b - a) / n
139
+ x_right = np.linspace(a + h, b, n)
138
140
  y_right = f(x_right)
139
141
 
140
142
  integral_approx = np.sum(y_right * h)
@@ -142,6 +144,7 @@ def right_riemann(f, a, b, h):
142
144
  return {
143
145
  "x_right": x_right,
144
146
  "y_right": y_right,
147
+ "n": n,
145
148
  "integral_approx": integral_approx,
146
149
  "a": a,
147
150
  "b": b,
@@ -267,8 +270,9 @@ def visualize_right_riemann(f, data):
267
270
  return fig
268
271
 
269
272
 
270
- def midpoint_riemann(f, a, b, h):
271
- x_mid = np.arange(a + h / 2, b, h)
273
+ def midpoint_riemann(f, a, b, n):
274
+ h = (b - a) / n
275
+ x_mid = np.linspace(a + h / 2, b - h / 2, n)
272
276
  y_mid = f(x_mid)
273
277
 
274
278
  integral_approx = np.sum(y_mid * h)
@@ -276,6 +280,7 @@ def midpoint_riemann(f, a, b, h):
276
280
  return {
277
281
  "x_mid": x_mid,
278
282
  "y_mid": y_mid,
283
+ "n": n,
279
284
  "integral_approx": integral_approx,
280
285
  "a": a,
281
286
  "b": b,
@@ -402,11 +407,9 @@ def visualize_midpoint_riemann(f, data):
402
407
  return fig
403
408
 
404
409
 
405
- def trapezoid_rule(f, a, b, h):
406
- x_points = np.arange(a, b, h)
407
- x_points = np.append(x_points, b)
408
- x_points = np.unique(x_points)
409
-
410
+ def trapezoid_rule(f, a, b, n):
411
+ h = (b - a) / n
412
+ x_points = np.linspace(a, b, n + 1)
410
413
  y_points = f(x_points)
411
414
 
412
415
  widths = np.diff(x_points)
@@ -416,6 +419,7 @@ def trapezoid_rule(f, a, b, h):
416
419
  "x_points": x_points,
417
420
  "y_points": y_points,
418
421
  "widths": widths,
422
+ "n": n,
419
423
  "integral_approx": integral_approx,
420
424
  "a": a,
421
425
  "b": b,
@@ -543,16 +547,11 @@ def visualize_trapezoid_rule(f, data):
543
547
 
544
548
  return fig
545
549
 
546
- def simpsons_13(f, a, b, h):
547
- n_float = (b - a) / h
548
- n = round(n_float)
549
-
550
- if not np.isclose(n_float, n) or n <= 0:
551
- raise ValueError("(b - a) must be a positive integer multiple of h.")
552
-
553
- if n % 2 != 0:
554
- raise ValueError("Simpson's 1/3 Rule requires an even number of subintervals.")
550
+ def simpsons_13(f, a, b, n):
551
+ if n <= 0 or n % 2 != 0:
552
+ raise ValueError("Simpson's 1/3 Rule requires a positive even number of subintervals.")
555
553
 
554
+ h = (b - a) / n
556
555
  x_points = np.linspace(a, b, n + 1)
557
556
  y_points = np.asarray(f(x_points))
558
557
 
@@ -563,7 +562,6 @@ def simpsons_13(f, a, b, h):
563
562
  + 2 * np.sum(y_points[2:-1:2])
564
563
  )
565
564
 
566
-
567
565
  return {
568
566
  "x_points": x_points,
569
567
  "y_points": y_points,
@@ -720,16 +718,11 @@ def visualize_simpsons_13(f, data):
720
718
 
721
719
  return fig
722
720
 
723
- def simpsons_38(f, a, b, h):
724
- n_float = (b - a) / h
725
- n = round(n_float)
726
-
727
- if not np.isclose(n_float, n) or n <= 0:
728
- raise ValueError("(b - a) must be a positive integer multiple of h.")
729
-
730
- if n % 3 != 0:
731
- raise ValueError("Simpson's 3/8 Rule requires a number of subintervals divisible by 3.")
721
+ def simpsons_38(f, a, b, n):
722
+ if n <= 0 or n % 3 != 0:
723
+ raise ValueError("Simpson's 3/8 Rule requires a positive number of subintervals divisible by 3.")
732
724
 
725
+ h = (b - a) / n
733
726
  x_points = np.linspace(a, b, n + 1)
734
727
  y_points = np.asarray(f(x_points))
735
728
 
@@ -740,7 +733,6 @@ def simpsons_38(f, a, b, h):
740
733
 
741
734
  integral_approx = (3 * h / 8) * np.sum(weights * y_points)
742
735
 
743
-
744
736
  return {
745
737
  "x_points": x_points,
746
738
  "y_points": y_points,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: executable_engineering
3
- Version: 0.1.52
3
+ Version: 0.1.53
4
4
  Summary: Demonstrative tools for the Executable Engineering textbook
5
5
  Home-page: https://github.com/themintlab/ExecutableEngineering/tree/main/executable_engineering
6
6
  Author: Michael Welland
@@ -1,4 +1,4 @@
1
- executable_engineering/__init__.py,sha256=o5FrSXnK0q_cdrSpqUVYTpLGTH8V27W8fx4impYXGq0,5459
1
+ executable_engineering/__init__.py,sha256=DtGSITN9phC5lIkKP-szsVjsBhzwlQKol4Ow5AoW7oU,5419
2
2
  executable_engineering/closedoptimization_module.py,sha256=7J6espVpgjRRwQvx35QXuaaigdX9R-P2wN5JTSpi5fI,14076
3
3
  executable_engineering/closedrootfinder_module.py,sha256=hQ6iWNi16RkZTaE_WPUEwkohmrYrAyU8WWSXO2EPLJY,6000
4
4
  executable_engineering/constrainedoptimization_module.py,sha256=rNqVnwGZdFRgc653dYM9iBy0WOcMtNF5GmtXBHzXV2k,5061
@@ -10,12 +10,12 @@ executable_engineering/integration_module.py,sha256=WVEJlSH6vZamt4gaoWYvPczcdIMV
10
10
  executable_engineering/linearsystems_module.py,sha256=w6UkwZu80gUz5bAIWY47xJbwaEVzR9tCcIBkMsKjIRk,18356
11
11
  executable_engineering/neuralnet_module.py,sha256=BV__TBBIZCrWwIIdwcXnBJ2Ki37BDlqMmR4YFHImkcg,16255
12
12
  executable_engineering/numerical_error_module.py,sha256=wxfYP8u29c19I2D6MxpQV3zDMV0DpS1QUqFpp3f6eGE,1204
13
- executable_engineering/numerical_integration_module.py,sha256=wY98eFnTsIxMoxwtWE9soROFemRl4anMpIhg-KfFVUA,22544
13
+ executable_engineering/numerical_integration_module.py,sha256=TMB3_Eqr4NBTjmeYMLlpZr_I4hwaykdvmEqxxK1AN04,22325
14
14
  executable_engineering/openoptimization_module.py,sha256=FJCnrgWS5G1Rz07F_5lxXdwBMdk0O7ll8epA-Y4gCvc,13083
15
15
  executable_engineering/openrootfinder_module.py,sha256=R_lPtCQsIGLXV-j_uDpQepImOOgtgA7I6qnhUPwWLLc,5944
16
16
  executable_engineering/optimization_module.py,sha256=GZtLSWY4VaF39HYg29HU3ZdU7yF-q5s2f8QlF6E1Uqw,12097
17
- executable_engineering-0.1.52.dist-info/licenses/LICENSE,sha256=Tg4nrt8rFhgpkPbIA8SWoCR3MlGLw0NufB8AE6-TH_o,1074
18
- executable_engineering-0.1.52.dist-info/METADATA,sha256=_HmtnN7U4BJmkD7Sbt9tGFL4wPxNdF2LAH4BF8uSz48,1648
19
- executable_engineering-0.1.52.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
20
- executable_engineering-0.1.52.dist-info/top_level.txt,sha256=0U5ATV5WGTLvN9rRSjQ54TyL-ztTyXaN3FzZ_QMq4HM,23
21
- executable_engineering-0.1.52.dist-info/RECORD,,
17
+ executable_engineering-0.1.53.dist-info/licenses/LICENSE,sha256=Tg4nrt8rFhgpkPbIA8SWoCR3MlGLw0NufB8AE6-TH_o,1074
18
+ executable_engineering-0.1.53.dist-info/METADATA,sha256=vhdn5XHqA2VsiJX29zeMxXkV0ugSsBZwjKliFxaa39M,1648
19
+ executable_engineering-0.1.53.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
20
+ executable_engineering-0.1.53.dist-info/top_level.txt,sha256=0U5ATV5WGTLvN9rRSjQ54TyL-ztTyXaN3FzZ_QMq4HM,23
21
+ executable_engineering-0.1.53.dist-info/RECORD,,