From cc4c61bc4d03f0b45ed0d862cdca14fbe56d50f0 Mon Sep 17 00:00:00 2001 From: lionarius Date: Mon, 25 Mar 2024 14:14:12 +0300 Subject: [PATCH] done --- Л3-В6/Программа/example.txt | 5 +++++ Л3-В6/Программа/src/window.py | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Л3-В6/Программа/example.txt b/Л3-В6/Программа/example.txt index 4275bd5..967d194 100644 --- a/Л3-В6/Программа/example.txt +++ b/Л3-В6/Программа/example.txt @@ -29,3 +29,8 @@ 22 -9 -3 2 300 0 -8 -21 -5 -3 15 3 15 4 16 -1 0 -2 -11 -2 -2 10 -150 -6 + +# task +8 -4 -1 33 +-18 15 6 -30 +0 7 -2 58 diff --git a/Л3-В6/Программа/src/window.py b/Л3-В6/Программа/src/window.py index 86dbf31..2f7a50b 100644 --- a/Л3-В6/Программа/src/window.py +++ b/Л3-В6/Программа/src/window.py @@ -207,6 +207,8 @@ class MainWindow(QMainWindow): matrix_a: np.matrix matrix_b: np.matrix + eps_input: InputField + n_input: InputField det_display: DisplayField cond_display: DisplayField @@ -230,9 +232,19 @@ class MainWindow(QMainWindow): label1 = QLabel("Вариант 6", self) layout.addWidget(label1) + inputs_row = QWidget() + inputs_row_layout = QHBoxLayout() + self.n_input = InputField(self, " n: ", "число строк", str(4), "left") self.n_input.on_change(lambda w: self.on_n_input_changed(w)) - layout.addWidget(self.n_input) + inputs_row_layout.addWidget(self.n_input) + + self.eps_input = InputField(self, " eps: ", "точность", str(0.001), "left") + self.eps_input.on_change(lambda w: self.on_eps_input_changed(w)) + inputs_row_layout.addWidget(self.eps_input) + + inputs_row.setLayout(inputs_row_layout) + layout.addWidget(inputs_row) buttons_row = QWidget() buttons_row_layout = QHBoxLayout() @@ -274,6 +286,17 @@ class MainWindow(QMainWindow): self.central_widget.setLayout(layout) + def on_eps_input_changed(self, widget: InputField): + on_input_float_number(widget) + + eps = widget.get_value() + try: + if float(eps) < 0: + eps = 0 + self.eps_input.set_value(eps) + except: + return + def on_random_button_clicked(self): n = int(self.n_input.get_value()) self.matrix_a = np.round(np.random.rand(n, n) * 10, 2) @@ -287,7 +310,11 @@ class MainWindow(QMainWindow): except: print("Numpy could not solve the system") - x = solution.iterative_method(self.matrix_a, self.matrix_b) + try: + eps = float(self.eps_input.get_value()) + except: + eps = 0 + x = solution.iterative_method(self.matrix_a, self.matrix_b, eps) print(f"Iterative solution: {x}") if x is None: @@ -346,6 +373,7 @@ class MainWindow(QMainWindow): def on_reset_button_clicked(self): self.n_input.set_value(str(4)) + self.eps_input.set_value(str(0.001)) self.set_matrix(task.A(), task.B()) def on_matrix_changed(self, widget: InputField):