3 files modified
2 files added
| | |
| | | where = ["src"] |
| | | |
| | | [project.scripts] |
| | | numint = "numint.Riemann:main" |
| | | numint = "numint.main:main" |
| | | |
| | |
| | | |
| | | def numint(f, a, b, epsilon=1e-3): |
| | | dx = b - a |
| | | x = [a, b] # debug only |
| | | y = [f(a), f(b)] |
| | | s_left = dx * y[0] |
| | | s_right = dx * y[1] |
| | | (n, parts) = (1, 1) |
| | | (n, parts) = (0, 1) |
| | | while abs(s_right - s_left) > epsilon: |
| | | x = [a, b] # debug only |
| | | parts = 2 * parts |
| | | dx = dx / 2 |
| | | n += 1 |
| | | print(n, " → ", parts) |
| | | # print(n, " → ", parts) |
| | | for i in range(1, parts, 2): |
| | | x.insert(i, a + i * dx) # debug only |
| | | x.insert(i, a + i * dx) |
| | | y.insert(i, f(a + i * dx)) |
| | | # print(i, end=" ") |
| | | # print() |
| | | # print(" ", x) |
| | | # print(" ", y) |
| | | s_left = sum(y[0:-1]) * dx |
| | | s_right = sum(y[1:]) * dx |
| | | return s_left, s_right |
| | | return x, y, s_left, s_right, n |
| | | |
| | | |
| | | def numint_compact(f, a, b, epsilon=1e-3): |
| | |
| | | parts = 2 * parts |
| | | dx = dx / 2 |
| | | n += 1 |
| | | print(n, " → ", parts) |
| | | for i in range(1, parts, 2): |
| | | # print(i, end=" ") |
| | | y = f(a + i*dx) |
| | | y_l += y |
| | | y_r += y |
| | | print() |
| | | # print(" ", x) |
| | | # print(" ", y) |
| | | s_left = y_l * dx |
| | | s_right = y_r * dx |
| | | return s_left, s_right |
New file |
| | |
| | | import matplotlib.pyplot as plt |
| | | |
| | | from numint.RiemannSum import numint |
| | | |
| | | def main(): |
| | | def f(x): return x**3 |
| | | (a,b) = (1,2) |
| | | (x, y, l, r, n) = numint(f, a, b, 0.5) |
| | | # print(l, r, n) |
| | | plt.step(x, y, label="x^3") |
| | | plt.step(x, y, where="post", label="x^3") |
| | | plt.plot(x,y, color="gray", alpha=0.3) |
| | | plt.show() |
| | | pass |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ui version="4.0"> |
| | | <class>MainWindow</class> |
| | | <widget class="QMainWindow" name="MainWindow"> |
| | | <property name="geometry"> |
| | | <rect> |
| | | <x>0</x> |
| | | <y>0</y> |
| | | <width>800</width> |
| | | <height>600</height> |
| | | </rect> |
| | | </property> |
| | | <property name="windowTitle"> |
| | | <string>MainWindow</string> |
| | | </property> |
| | | <widget class="QWidget" name="centralwidget"> |
| | | <widget class="QWidget" name=""> |
| | | <property name="geometry"> |
| | | <rect> |
| | | <x>11</x> |
| | | <y>11</y> |
| | | <width>328</width> |
| | | <height>71</height> |
| | | </rect> |
| | | </property> |
| | | <layout class="QVBoxLayout" name="verticalLayout"> |
| | | <item> |
| | | <layout class="QHBoxLayout" name="horizontalLayout"> |
| | | <item> |
| | | <widget class="QLabel" name="label"> |
| | | <property name="text"> |
| | | <string>a</string> |
| | | </property> |
| | | </widget> |
| | | </item> |
| | | <item> |
| | | <widget class="QLineEdit" name="lineEdit"/> |
| | | </item> |
| | | <item> |
| | | <widget class="QLabel" name="label_2"> |
| | | <property name="text"> |
| | | <string>b</string> |
| | | </property> |
| | | </widget> |
| | | </item> |
| | | <item> |
| | | <widget class="QLineEdit" name="lineEdit_2"/> |
| | | </item> |
| | | </layout> |
| | | </item> |
| | | <item> |
| | | <layout class="QHBoxLayout" name="horizontalLayout_2"> |
| | | <item> |
| | | <spacer name="horizontalSpacer"> |
| | | <property name="orientation"> |
| | | <enum>Qt::Horizontal</enum> |
| | | </property> |
| | | <property name="sizeHint" stdset="0"> |
| | | <size> |
| | | <width>40</width> |
| | | <height>20</height> |
| | | </size> |
| | | </property> |
| | | </spacer> |
| | | </item> |
| | | <item> |
| | | <widget class="QPushButton" name="pushButton"> |
| | | <property name="text"> |
| | | <string>Ok</string> |
| | | </property> |
| | | </widget> |
| | | </item> |
| | | </layout> |
| | | </item> |
| | | </layout> |
| | | </widget> |
| | | </widget> |
| | | <widget class="QMenuBar" name="menubar"> |
| | | <property name="geometry"> |
| | | <rect> |
| | | <x>0</x> |
| | | <y>0</y> |
| | | <width>800</width> |
| | | <height>26</height> |
| | | </rect> |
| | | </property> |
| | | </widget> |
| | | <widget class="QStatusBar" name="statusbar"/> |
| | | </widget> |
| | | <resources/> |
| | | <connections/> |
| | | </ui> |
| | |
| | | |
| | | |
| | | class RiemannSumTestCase(unittest.TestCase): |
| | | |
| | | """ |
| | | TODO (Aufgabe) Schreiben Sie Kriterien in Unittest |
| | | """ |
| | | def test_split_interval(self): |
| | | split(iteration=6) |
| | | |
| | | def test_numint(self): |
| | | def fn(x) : return x**2 |
| | | (a, b) = (0, 2) |
| | | (l, r) = numint(fn, a, b) |
| | | print(l, r) |
| | | (l, r, *_) = numint(fn, a, b) |
| | | # print(l, r) # print Take too much place on screen |
| | | pass |
| | | |
| | | def test_numint_compact(self): |