Simpson-Regel. Trapez Regel Beschreibung hinzugefügt
This commit is contained in:
parent
dfc9ba19dc
commit
fbd6476bad
45
src/klausurvorbereitung/integration_simpson.py
Normal file
45
src/klausurvorbereitung/integration_simpson.py
Normal file
@ -0,0 +1,45 @@
|
||||
"""
|
||||
Simpson-Regel
|
||||
|
||||
Integration der funktion:
|
||||
2
|
||||
I = | (x + sin(x))^(2/3)) dx
|
||||
0
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import scipy.integrate as ig
|
||||
|
||||
# Parameter
|
||||
x_0 = 0
|
||||
x_E = 2
|
||||
n = 10
|
||||
N = 201
|
||||
pr = 6
|
||||
|
||||
f = lambda x: np.sqrt(x + np.sin(x))
|
||||
|
||||
# Berechnung
|
||||
for k in range(0, n):
|
||||
x_data = np.linspace(x_0, x_E, N)
|
||||
y_data = f(x_data)
|
||||
I = ig.simpson(y=y_data, x=x_data)
|
||||
print(f"I = {I:#.16g} | N = {N:g}")
|
||||
N *= 2
|
||||
print(f"I = {I:#.{pr}g}")
|
||||
|
||||
"""
|
||||
Ausgabe:
|
||||
|
||||
I = 2.490070783046884 | N = 201
|
||||
I = 2.490260152603558 | N = 402
|
||||
I = 2.490326897146905 | N = 804
|
||||
I = 2.490350466364332 | N = 1608
|
||||
I = 2.490358796310514 | N = 3216
|
||||
I = 2.490361741357393 | N = 6432
|
||||
I = 2.490362782708113 | N = 12864
|
||||
I = 2.490363150933651 | N = 25728
|
||||
I = 2.490363281138151 | N = 51456
|
||||
I = 2.490363327177379 | N = 102912
|
||||
I = 2.49036
|
||||
"""
|
||||
@ -1,4 +1,6 @@
|
||||
"""
|
||||
Trapez-Regel
|
||||
|
||||
Integration der funktion:
|
||||
2
|
||||
I = | (x + sin(x))^(2/3)) dx
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user