alexbprofit / academicpaperapp

1 stars 0 forks source link

addon #2

Open alexbprofit opened 3 years ago

alexbprofit commented 3 years ago
import math

def f(param, x, type):
    if type == 1:
        y = 0
        for i in range(len(param)):
            y = param[i] * math.pow(x, i) + y
        return y
    else:
        if type == 2:
            return x - param[0] - param[1] * math.sin(x)
        elif type == 4:
            try:
                return param[0] - math.log(x, math.e) - param[1]*pow(x, param[2])
            except ValueError:
                pass
        else:
            return x - math.exp(param[0] * (x - 1))

def dx(param, x, type):
    return abs(f(param, x, type))

def df(param, x, type):
    if type == 1:
        y = 0
        for i in range(1, len(param), 1):
            y = y + (i * param[i] * math.pow(x, i))
        return y
    else:
        if type == 2:
            return 1 - param[1] * math.cos(x)
        elif type == 4:
            return -1/x - param[1]*param[2]*pow(x, param[2] - 1)
        else:
            return 1 - param[0] * math.exp(param[0] * (x - 1))

def ddf(param, x, type):
    y = 0
    for i in range(2, len(param), 1):
        y = y + (i * (i - 1) * param[i] * math.pow(x, i))
    return y

def decomp(param, p, q, eps, type=3):
    intervals = []
    i = p
    t = 10.0 * eps

    while i < q:
        if not isinstance(f(param, i, type), float):
            i = i + t
        else:
            if f(param, i, type) * f(param, i + t, type) < 0:
                t = t / 10
                i = i + t
            else:
                i = i + t
                if t < eps:
                    intervals.append([i - 3 * t, i + 3 * t])
                    if type == 1 or type == 3:
                        if len(intervals) == len(param):
                            break
                    t = 10 * eps
    return intervals

# Виконана перевірка
def newtonRaphson(l, r, eps, param, type):
    condition = True
    x0 = (l + r) / 2.0
    count = 0
    while condition:
        x1 = x0 - f(param, x0, type) / df(param, x0, type)
        if abs(x1 - x0) < eps:
            condition = False
        else:
            x0 = x1
            count += 1
    return x1, count

def samesign(a, b):
    return a * b > 0

def Bisect(fx, l, r, eps, param, type):
    step = 0
    while True:
        midpoint = (l + r) / 2.0
        if samesign(fx(param, l, type), fx(param, midpoint, type)):
            l = midpoint
        else:
            r = midpoint
        if dx(param, midpoint, type) < eps:
            break
        step = step + 1
    return midpoint, step

########################
# проблемнв зона
def simplefleft(param, x, type):
    return f(param, x, type) - param[1] * x

def simpleIterationMethod(l, eps, param, type):
    condition = True
    x0 = l
    count = 0
    while condition:
        if param[1] != 0:
            x1 = simplefleft(param, x0, type) / -param[1]
        else:
            x1 = simplefleft(param, x0, type)
        if abs(x1 - x0) < eps:
            condition = False
        x0 = x1
        count += 1
    return x1, count

########################
def secantMethod(l, r, eps, param, type):
    x1 = (l + r) / 2.0
    x2 = f(param, x1, type)
    iterate = 0
    maxIteration = 100
    cond = True
    while cond and iterate < maxIteration:
        y1 = x2 - ((f(param, x2, type) * (x2 - x1)) / (f(param, x2, type) - f(param, x1, type)))
        if abs(y1 - x2) < eps:
            cond = False
        x1 = x2
        x2 = y1
        iterate += 1
    return x1, iterate

def steffencenMethod(l, r, eps, param, type):
    iterate = 0
    maxIteration = 100
    cond = True
    x0 = (l + r) / 2.0
    while cond and iterate < maxIteration:
        x1 = x0 - ((f(param, x0, type) ** 2) / (f(param, x0 + f(param, x0, type), type) - f(param, x0, type)))
        if abs(x0 - x1) < eps:
            cond = False
        x0 = x1
        iterate += 1
    return x1, iterate

def easeNewtomRaphsonMethod(l, r, eps, param, type):
    iterate = 0
    maxIteration = 100
    x0 = (l + r) / 2.0
    j = x0
    cond = True
    while cond and iterate < maxIteration:
        x1 = x0 - (f(param, x0, type) / df(param, j, type))
        if abs(x1 - x0) < eps:
            cond = False
        x0 = x1
        iterate += 1
    return x1, iterate

def modifiedNewtonRaphsonMethod(l, r, eps, param, type, m=1):
    condition = True
    x0 = (l + r) / 2.0
    count = 0
    while condition:
        x1 = x0 - m * (f(param, x0, type) / df(param, x0, type))
        if abs(x1 - x0) < eps:
            condition = False
        else:
            x0 = x1
            count += 1
    return x1, count

def HeiliMethod(l, r, eps, param, type):
    iterate = 0
    maxIteration = 100
    cond = True
    x0 = (l + r) / 2.0
    while cond and iterate < maxIteration:
        x1 = x0 - ((f(param, x0, type) * df(param, x0,type)) / (math.pow(df(param, x0,type), 2) - (f(param, x0,type) * ddf(param, x0,type))))
        if abs(x1 - x0) < eps:
            cond = False
        x0 = x1
        iterate += 1
    return x1, type

def extendNewtonMethod(l, r, eps, param, type):
    iterate = 0
    maxIteration = 100
    cond = True
    x0 = (l + r) / 2.0
    root = newtonRaphson(l, r, eps, param, type)
    while cond and iterate < maxIteration:
        x1 = root[0] - (
                (ddf(param, x0, type) * math.pow(f(param, x0, type), 2)) / (2 * math.pow(df(param, x0, type), 2)))
        if abs(x1 - x0) < eps:
            cond = False
        x0 = x1
        iterate += 1
    return x1, iterate

def interpolationMethod(l, r, eps, param, type):
    x1 = (l + r) / 2.0
    x2 = f(param, x1, type)
    iterate = 0
    maxIteration = 100
    cond = True
    while cond and iterate < maxIteration:
        y1 = x2 - ((f(param, x2, type) * (x2 - x1)) / (f(param, x2, type) - f(param, x1, type)))
        if abs(y1 - x2) < eps:
            cond = False
        x1 = x2
        x2 = y1
        iterate += 1
    return x1, iterate

def subNewtonMethod(l, r, eps, param, type):
    h0 = 1
    iterate = 0
    maxIteration = 100
    cond = True
    x0 = (l + r) / 2.0
    while cond and iterate < maxIteration:
        hk = 0.5 * h0
        x1 = x0 - ((hk * f(param, x0, type)) / (f(param, x0 + hk, type) - f(param, x0, type)))
        if abs(x1 - x0) < eps:
            cond = False
        x0 = x1
        h0 = hk
    return x1, iterate

def main(f, param, num, eps, type):
    testroots = []
    intervals = decomp(param, -100, 100, eps, type)
    if num == 2:
        print("Метод половинного поділу")
        for i in range(len(intervals)):
            testroot, count = Bisect(f, intervals[i][0], intervals[i][1], eps, param, type)
            testroots.append([testroot, count])
    elif num == 1:
        print("Метод Ньютона")
        for i in range(len(intervals)):
            testroot, count = newtonRaphson(intervals[i][0], intervals[i][1], eps, param, type)
            testroots.append([testroot, count])
    elif num == 3:
        print("Метод простої ітерації")
        for i in range(len(intervals)):
            testroot, count = simpleIterationMethod(intervals[i][0], eps, param, type)
            testroots.append([testroot, count])
    elif num == 4:
        print("Метод січних.")
        for i in range(len(intervals)):
            testroot, count = secantMethod(intervals[i][0], intervals[i][1], eps, param, type)
            testroots.append([testroot, count])
    elif num == 6:
        print("Метод Ньютона(спрощений).")
        for i in range(len(intervals)):
            testroot, count = easeNewtomRaphsonMethod(intervals[i][0], intervals[i][1], eps, param, type)
            testroots.append([testroot, count])
    elif num == 7:
        print("Метод Ньютона(модифікований).")
        for i in range(len(intervals)):
            testroot, count = modifiedNewtonRaphsonMethod(intervals[i][0], intervals[i][1], eps, param, type)
            testroots.append([testroot, count])
    elif num == 9:
        print("Метод Ньютона(розширений).")
        for i in range(len(intervals)):
            testroot, count = extendNewtonMethod(intervals[i][0], intervals[i][1], eps, param, type)
            testroots.append([testroot, count])
    elif num == 10:
        print("Метод хорд.")
        for i in range(len(intervals)):
            testroot, count = interpolationMethod(intervals[i][0], intervals[i][1], eps, param, type)
            testroots.append([testroot, count])
    elif num == 11:
        print("Метод Ньютона(різницевий).")
        for i in range(len(intervals)):
            testroot, count = subNewtonMethod(intervals[i][0], intervals[i][1], eps, param, type)
            testroots.append([testroot, count])
    elif num == 5:
        print("Метод Стеффенсена.")
        for i in range(len(intervals)):
            testroot, count = steffencenMethod(intervals[i][0], intervals[i][1], eps, param, type)
            testroots.append([testroot, count])
    ######################################
    for i in range(len(testroots)):
        print(testroots[i])
    if len(testroots) < 1:
        return math.nan
    else:
        return testroots
alexbprofit commented 3 years ago
import sys

import matplotlib
from PyQt5 import QtGui
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import top
import numpy as np
from matplotlib.backends.backend_qt5agg import (
        FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
matplotlib.use('qt5agg')
from matplotlib.figure import Figure

class SetType(QMainWindow):
    def __init__(self):
        super(SetType, self).__init__()
        self.params = []
        self.rbtn1 = QRadioButton("Поліном")
        self.rbtn2 = QRadioButton("Рівняння Кеплера")
        self.rbtn3 = QRadioButton("доля інфікованого населення")
        self.rbtn4 = QRadioButton("y = bx^m - ln(x) - a")
        self.widget = QWidget()
        self.l = QVBoxLayout()
        self.l.maximumSize()
        self.l.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.saveChange = QPushButton("Зберегти")
        self.saveChange.pressed.connect(self.change)
        self.priority = QLineEdit()
        self.priority.setDisabled(True)
        self.check = 0
        self.l.addWidget(self.rbtn1)
        self.l.addWidget(self.rbtn2)
        self.l.addWidget(self.rbtn3)
        self.l.addWidget(self.rbtn4)
        self.l.addWidget(self.priority)
        self.l.addWidget(self.saveChange)
        self.r = QVBoxLayout()
        self.r.setAlignment(Qt.AlignmentFlag.AlignRight)
        self.rb1 = QRadioButton("Ньютона")
        self.rb2 = QRadioButton("Половинного поділу")
        self.rb3 = QRadioButton("Простої ітерації")
        self.rb4 = QRadioButton("Січних")
        self.rb5 = QRadioButton("Стефенсена")
        self.rb6 = QRadioButton("Ньютона(спрощений)")
        self.rb7 = QRadioButton("Ньютона(модиф.)")
        self.rb9 = QRadioButton("Ньютона(розшир.)")
        self.rb10 = QRadioButton("Хорд")
        self.rb11 = QRadioButton("Ньютона(різницевий)")
        self.r.addWidget(self.rb1)
        self.r.addWidget(self.rb2)
        self.r.addWidget(self.rb3)
        self.r.addWidget(self.rb4)
        self.r.addWidget(self.rb5)
        self.r.addWidget(self.rb6)
        self.r.addWidget(self.rb7)
        self.r.addWidget(self.rb9)
        self.r.addWidget(self.rb10)
        self.r.addWidget(self.rb11)
        self.saveMode = QPushButton("Зберегти")
        self.saveMode.pressed.connect(self.changes)
        self.r.addWidget(self.saveMode)

        self.centralLayout = QVBoxLayout()
        self.nums = 0
        self.descLayout = QVBoxLayout()
        self.descLayout.setAlignment(Qt.AlignmentFlag.AlignTop)

        self.desc = QLabel()

        self.inputDataLayout = QHBoxLayout()
        self.inputDataLayout.setAlignment(Qt.AlignmentFlag.AlignCenter)

        self.hint = QLabel("a0: ")
        self.hint.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.inputParameter = QLineEdit()
        self.inputParameter.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.accuracy = QLabel("Точність")
        self.accuracy.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.accuracyParameter = QLineEdit()
        self.accuracyParameter.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.confirmButton = QPushButton("Зберегти")
        self.confirmButton.pressed.connect(self.saveCheck)
        self.inputDataLayout.addWidget(self.hint)
        self.inputDataLayout.addWidget(self.inputParameter)
        self.inputDataLayout.addWidget(self.accuracy)
        self.inputDataLayout.addWidget(self.accuracyParameter)
        self.inputDataLayout.addWidget(self.confirmButton)

        self.root = QLabel()

        self.buttons = QHBoxLayout()

        self.addParamButton = QPushButton("Ввести")
        self.addParamButton.pressed.connect(self.accept)
        self.addParamButton.setFixedSize(200, 32)
        self.printResultButton = QPushButton("Обчислити")
        self.printResultButton.setFixedSize(200, 32)
        self.printResultButton.pressed.connect(self.confirm)
        self.buttons.addWidget(self.addParamButton)
        self.buttons.addWidget(self.printResultButton)
        self.descLayout.addWidget(self.desc)
        self.descLayout.addLayout(self.inputDataLayout)
        self.descLayout.addLayout(self.buttons)
        self.descLayout.addWidget(self.root)

        self.static_canvas = FigureCanvas(Figure(figsize=(300, 180)))

        self.faceResult = QVBoxLayout()
        self.result = QLabel()
        self.resetWindow = QPushButton("Очистити")
        self.resetWindow.pressed.connect(self.repeat)

        self.exitProgram = QPushButton("Завершити роботу")
        self.exitProgram.pressed.connect(sys.exit)

        self.faceResult.addWidget(self.result)
        self.faceResult.addWidget(self.resetWindow)
        self.faceResult.addWidget(self.exitProgram)

        self.centralLayout.addLayout(self.descLayout)
        self.centralLayout.addWidget(self.static_canvas)
        self.centralLayout.addLayout(self.faceResult)

        self.aaa = 0
        self.bbb = 0

        self.h = QHBoxLayout()
        self.h.addLayout(self.l)
        self.h.addLayout(self.centralLayout)
        self.h.addLayout(self.r)
        self.widget.setLayout(self.h)
        self.setCentralWidget(self.widget)
        self.show()

    def hover(self):
        self.style = QStyle()
        self.style.setProperty("background-color", QColor().green())

    def saveCheck(self):
        self.acc = float(self.accuracyParameter.text())

    def repeat(self):
        self.removeToolBar(self.toolBar)
        self.params = []
        self.rbtn1 = QRadioButton("Поліном")
        self.rbtn2 = QRadioButton("Рівняння Кеплера")
        self.rbtn3 = QRadioButton("доля інфікованого населення")
        self.rbtn4 = QRadioButton("y = bx^m - ln(x) - a")
        self.widget = QWidget()
        self.l = QVBoxLayout()
        self.l.maximumSize()
        self.l.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.saveChange = QPushButton("Зберегти")
        self.saveChange.pressed.connect(self.change)
        self.priority = QLineEdit()
        self.priority.setDisabled(True)
        self.check = 0
        self.l.addWidget(self.rbtn1)
        self.l.addWidget(self.rbtn2)
        self.l.addWidget(self.rbtn3)
        self.l.addWidget(self.rbtn4)
        self.l.addWidget(self.priority)
        self.l.addWidget(self.saveChange)
        self.r = QVBoxLayout()
        self.r.setAlignment(Qt.AlignmentFlag.AlignRight)
        self.rb1 = QRadioButton("Ньютона")
        self.rb2 = QRadioButton("Половинного поділу")
        self.rb3 = QRadioButton("Простої ітерації")
        self.rb4 = QRadioButton("Січних")
        self.rb5 = QRadioButton("Стефенсена")
        self.rb6 = QRadioButton("Ньютона(спрощений)")
        self.rb7 = QRadioButton("Ньютона(модиф.)")
        self.rb9 = QRadioButton("Ньютона(розшир.)")
        self.rb10 = QRadioButton("Хорд")
        self.rb11 = QRadioButton("Ньютона(різницевий)")
        self.r.addWidget(self.rb1)
        self.r.addWidget(self.rb2)
        self.r.addWidget(self.rb3)
        self.r.addWidget(self.rb4)
        self.r.addWidget(self.rb5)
        self.r.addWidget(self.rb6)
        self.r.addWidget(self.rb7)
        self.r.addWidget(self.rb9)
        self.r.addWidget(self.rb10)
        self.r.addWidget(self.rb11)
        self.saveMode = QPushButton("Зберегти")
        self.saveMode.pressed.connect(self.changes)
        self.r.addWidget(self.saveMode)

        self.centralLayout = QVBoxLayout()
        self.nums = 0
        self.descLayout = QVBoxLayout()
        self.descLayout.setAlignment(Qt.AlignmentFlag.AlignTop)

        self.desc = QLabel()

        self.inputDataLayout = QHBoxLayout()
        self.inputDataLayout.setAlignment(Qt.AlignmentFlag.AlignCenter)

        self.hint = QLabel("a0: ")
        self.hint.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.inputParameter = QLineEdit()
        self.inputParameter.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.accuracy = QLabel("Точність")
        self.accuracy.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.accuracyParameter = QLineEdit()
        self.accuracyParameter.setAlignment(Qt.AlignmentFlag.AlignLeft)
        self.confirmButton = QPushButton("Зберегти")
        self.confirmButton.pressed.connect(self.saveCheck)
        self.inputDataLayout.addWidget(self.hint)
        self.inputDataLayout.addWidget(self.inputParameter)
        self.inputDataLayout.addWidget(self.accuracy)
        self.inputDataLayout.addWidget(self.accuracyParameter)
        self.inputDataLayout.addWidget(self.confirmButton)

        self.root = QLabel()

        self.buttons = QHBoxLayout()

        self.addParamButton = QPushButton("Ввести")
        self.addParamButton.pressed.connect(self.accept)
        self.addParamButton.setFixedSize(200, 32)
        self.printResultButton = QPushButton("Обчислити")
        self.printResultButton.setFixedSize(200, 32)
        self.printResultButton.pressed.connect(self.confirm)
        self.buttons.addWidget(self.addParamButton)
        self.buttons.addWidget(self.printResultButton)
        self.descLayout.addWidget(self.desc)
        self.descLayout.addLayout(self.inputDataLayout)
        self.descLayout.addLayout(self.buttons)
        self.descLayout.addWidget(self.root)

        self.static_canvas = FigureCanvas(Figure(figsize=(300, 180)))

        self.faceResult = QVBoxLayout()
        self.result = QLabel()
        self.resetWindow = QPushButton("Очистити")
        self.resetWindow.pressed.connect(self.repeat)

        self.exitProgram = QPushButton("Завершити роботу")
        self.exitProgram.pressed.connect(sys.exit)

        self.faceResult.addWidget(self.result)
        self.faceResult.addWidget(self.resetWindow)
        self.faceResult.addWidget(self.exitProgram)

        self.centralLayout.addLayout(self.descLayout)
        self.centralLayout.addWidget(self.static_canvas)
        self.centralLayout.addLayout(self.faceResult)

        self.aaa = 0
        self.bbb = 0

        self.h = QHBoxLayout()
        self.h.addLayout(self.l)
        self.h.addLayout(self.centralLayout)
        self.h.addLayout(self.r)
        self.widget.setLayout(self.h)
        self.setCentralWidget(self.widget)
        self.show()

    def change(self):
        self.title = "Вибране рівняння:  "
        if self.rbtn1.isChecked():
            self.desc.setText(self.title + "y = a0 + a1*x + a2*x^2 + ..., a0, a1, ...  \n - параметри")
            self.check = 1
            self.priority.setDisabled(False)
            self.aaa += 1
            if self.aaa == 2:
                self.xy = int(self.priority.text())
        elif self.rbtn2.isChecked():
            self.desc.setText(self.title + "y = x - a - b*sin(x), a, b - параметри")
            self.check = 2
            self.priority.setDisabled(True)
        elif self.rbtn3.isChecked():
            self.desc.setText(self.title + "y = x - e^(a*(x-1)), a - параметр")
            self.check = 3
            self.priority.setDisabled(True)
        elif self.rbtn4.isChecked():
            self.desc.setText(self.title + self.rbtn4.text() + ",a,b,m - параметри")
            self.check = 4
            self.priority.setDisabled(True)
        else:
            self.warning("Вкажіть тип рівняння")

    def changes(self):
        if self.rb1.isChecked():
            self.nums = 1
        elif self.rb2.isChecked():
            self.nums = 2
        elif self.rb3.isChecked():
            self.nums = 3
        elif self.rb4.isChecked():
            self.nums = 4
        elif self.rb5.isChecked():
            self.nums = 5
        elif self.rb6.isChecked():
            self.nums = 6
        elif self.rb7.isChecked():
            self.nums = 7
        elif self.rb9.isChecked():
            self.nums = 9
        elif self.rb10.isChecked():
            self.nums = 10
        elif self.rb11.isChecked():
            self.nums = 11
        else:
            self.warning("Вкажіть метод знаходження числовго розв'язку")

    def plot(self):
        self.mainWidget.close()
        self.bbb += 1
        if self.bbb >= 2:
            self.removeToolBar(self.toolBar)

        if self.check == 0 or self.nums == 0:
            self.warning("Вкажіть тип рівняння та/або метод знаходження числового розв'язку")
        else:
            self._static_ax = self.static_canvas.figure.subplots()
            t = np.linspace(-10, 10, 120)

            xs = []
            for i in range(len(t)):
                x = top.f(self.params, t[i], self.check)
                xs.append(x)

            z = [0 for _ in range(len(t))]
            self._static_ax.plot(t, xs)
            self._static_ax.plot(z, xs)
            self._static_ax.plot(t, z)
            self.toolBar = NavigationToolbar(self.static_canvas, self)
            self.addToolBar(self.toolBar)
            self.perform()

    def perform(self):
        string = ''
        result = top.main(top.f, self.params, self.nums, self.acc, self.check)
        print(result)
        for i in range(len(result)):
            string += "%.8f" % (result[i][0]) + "\t" + str(result[i][1]) + "\n"

        self.result.setText("Корені:" + "\n" + string)

    def confirm(self):
        if len(self.params) != self.xy + 1:
            self.warning("Введіть всі параметри")
        else:
            self.mainWidget = QMainWindow()
            self.windows = QWidget()

            self.msg = QLabel()
            self.msg.setFont(QFont("Arial", 18, 50, False))

            self.msg.setText("Підтвердити введені дані?")
            self.msgVLayout = QVBoxLayout()
            self.msgHLayout = QHBoxLayout()

            self.acceptButton = QPushButton("Так")
            self.rejectButton = QPushButton("Ні")

            self.acceptButton.pressed.connect(self.plot)
            self.rejectButton.pressed.connect(self.redirectToBack)

            self.msgHLayout.addWidget(self.acceptButton)
            self.msgHLayout.addWidget(self.rejectButton)

            self.msgVLayout.addWidget(self.msg)
            self.msgVLayout.addLayout(self.msgHLayout)

            self.windows.setLayout(self.msgVLayout)
            self.mainWidget.setCentralWidget(self.windows)
            self.mainWidget.show()

    def warning(self, texts):
        self.warnWindow = QMainWindow()
        self.warnMsg = QWidget()
        self.warnlayout = QVBoxLayout()
        self.text = QLabel(texts)
        self.acceptButtons = QPushButton("ОК")
        self.acceptButtons.pressed.connect(self.warnWindow.close)
        self.text.setFont(QFont("Arial", 18, 50, False))
        self.warnlayout.addWidget(self.text)
        self.warnlayout.addWidget(self.acceptButtons)
        self.warnMsg.setLayout(self.warnlayout)
        self.warnWindow.setCentralWidget(self.warnMsg)
        self.warnWindow.show()

    def redirectToBack(self):
        self.params = []
        self.mainWidget.close()

    def accept(self):
        self.title = "Кінцеве рівняння:  "
        string = self.title + 'y = '
        if self.nums == 0 or self.check == 0:
            self.warning("Вкажіть тип рівняння та/або метод знаходження числовго розв'язку")
        else:
            if self.check == 1:
                if len(self.params) == self.xy + 1:
                    self.addParamButton.setText("Друк рівняння")
                    for i in range(len(self.params)):
                        if i == 0:
                            string += "%.6f*x^%.2f" % (self.params[i], i)
                        elif self.params[i] < 0:
                            string += "-%.6f*x^%.2f" % (abs(self.params[i]), i)
                        else:
                            string += "+%.6f*x^%.2f" % (abs(self.params[i]), i)
                    self.root.setText(string)
                else:
                    try:
                        self.data = compile(self.inputParameter.text(), 'string', 'eval')
                    except SyntaxError:
                        self.warning("Поле введення параметру не може бути порожнім")
                    else:
                        self.params.append(eval(self.data))
                        self.inputParameter.clear()
                        self.hint.setText("a{}: ".format(len(self.params)))
            else:
                if self.check == 2:
                    self.xy = 1
                elif self.check == 4:
                    self.xy = 2
                else:
                    self.xy = 0
                if len(self.params) == self.xy + 1:
                    if self.check == 2:
                        self.addParamButton.setText("Друк рівняння")
                        if self.params[0] < 0:
                            string += "x + %.6f - %.6f*sin(x)" % (self.params[0], self.params[1])
                        elif self.params[1] < 0:
                            string += "x - %.6f + %.6f*sin(x)" % (self.params[0], self.params[1])
                        elif self.params[0] < 0 and self.params[1] < 0:
                            string += "x + %.6f + %.6f*sin(x)" % (self.params[0], self.params[1])
                        else:
                            string += "x - %.6f - %.6f*sin(x)" % (self.params[0], self.params[1])
                    elif self.check == 4:
                        self.addParamButton.setText("Друк рівняння")
                        if self.params[0] < 0:
                            string += "-%.6f - ln(x) - %.6f*x^%.6f" % (self.params[0], self.params[1], self.params[2])
                        elif self.params[1] < 0:
                            string += "%.6f - ln(x) + %.6f*x^%.6f" % (self.params[0], self.params[1], self.params[2])
                        elif self.params[0] < 0 and self.params[1] < 0:
                            string += "-%.6f - ln(x) + %.6f*x^%.6f" % (self.params[0], self.params[1], self.params[2])
                        else:
                            string += "%.6f - ln(x) - %.6f*x^%.6f" % (self.params[0], self.params[1], self.params[2])
                    else:
                        if self.params[0] < 0:
                            string += "x - e^(-%.6f*(x - 1))" % (abs(self.params[0]))
                        else:
                            string += "x - e^(-%.6f*(x - 1))" % (abs(self.params[0]))
                    self.root.setText(string)
                else:
                    try:
                        self.data = compile(self.inputParameter.text(), 'string', 'eval')
                    except SyntaxError:
                        self.warning("Поле введення параметру не може бути порожнім")
                    else:
                        self.params.append(eval(self.data))
                        self.inputParameter.clear()
                        self.hint.setText("a{}: ".format(len(self.params)))

if __name__ == '__main__':
    qapp = QApplication(sys.argv)
    start = SetType()
    sys.exit(qapp.exec_())