Esempio n. 1
0
 def setupUi(self, MainWindow):
     super(MyMainWindow, self).setupUi(MainWindow)
     self.plotW = PlotWidget(self.tab_2)
     self.gridLayout_2.addWidget(self.plotW)
     self.GraphicalButton.clicked.connect(self.graphicalButtonClicked)
     self.analyticalButton.clicked.connect(self.analyticalButtonClicked)
     self.CnBW = CnBW()
     self.CnBW.setupUi(self.tab_4)
     self.NewtoneW = NewtoneWidget()
     self.NewtoneW.setupUi(self.tab_5)
     self.SInRW = SInRWidget()
     self.SInRW.setupUi(self.tab_6)
Esempio n. 2
0
class MyMainWindow(Ui_MainWindow):
    def graphicalButtonClicked(self):
        color1 = None
        if self.f1colorBox.currentIndex() == 0:
            color1 = 'r'
        elif self.f1colorBox.currentIndex() == 1:
            color1 = 'b'
        elif self.f1colorBox.currentIndex() == 2:
            color1 = 'g'
        elif self.f1colorBox.currentIndex() == 3:
            color1 = 'y'
        elif self.f1colorBox.currentIndex() == 4:
            color1 = 'm'
        elif self.f1colorBox.currentIndex() == 5:
            color1 = 'c'

        color2 = None
        if self.f2colorBox.currentIndex() == 0:
            color2 = 'r'
        elif self.f2colorBox.currentIndex() == 1:
            color2 = 'b'
        elif self.f2colorBox.currentIndex() == 2:
            color2 = 'g'
        elif self.f2colorBox.currentIndex() == 3:
            color2 = 'y'
        elif self.f2colorBox.currentIndex() == 4:
            color2 = 'm'
        elif self.f2colorBox.currentIndex() == 5:
            color2 = 'c'

        expr1 = parse_expr(self.f1Edit.text())
        expr2 = parse_expr(self.f2Edit.text())

        f1 = lambdify(x, expr1, 'numpy')
        f2 = lambdify(x, expr2, 'numpy')

        try:
            minX = float(self.minxEdit.text())
            maxX = float(self.maxxEdit.text())
        except:
            QMessageBox.warning(self, "Warning", "Min and max values error type.")
            return

        if minX <= maxX:
            x1 = np.linspace(minX, maxX, (maxX-minX)*1000)
            self.plotW.figure.clf()
            self.plotW.plot(x1, f1(x1), color1)
            self.plotW.plot(x1, f2(x1), color2)
        else:
            QMessageBox.warning(self, "Warning", "Min value must be smaller than max value")

    def analyticalButtonClicked(self):
        self.derTableWidget.clear()
        self.tableWidget.clear()
        self.tableWidget.setRowCount(0)
        self.derTableWidget.setColumnCount(0)
        expr = parse_expr(self.fEdit.text())
        f = lambdify(x, expr, 'numpy')
        diff = expr.diff(x)
        diffroots = solve(diff, x)
        diffroots.insert(0, float("-inf"))
        diffroots.append(float("inf"))
        colPosition = self.derTableWidget.columnCount()
        self.derTableWidget.setRowCount(2)
        self.derTableWidget.insertColumn(colPosition)
        self.derTableWidget.setItem(0, colPosition, QTableWidgetItem("DerInterval"))
        self.derTableWidget.setItem(1, colPosition, QTableWidgetItem("Sign f(x)"))
        for i in range(len(diffroots)):
            colPosition = self.derTableWidget.columnCount()
            self.derTableWidget.insertColumn(colPosition)
            self.derTableWidget.setItem(0, colPosition, QTableWidgetItem(("%s"%str(diffroots[i]))))
            self.derTableWidget.setItem(1, colPosition, QTableWidgetItem(str(sign(f(diffroots[i])))))

        xspace = np.linspace(int(diffroots[1]-100), int(diffroots[len(diffroots)-2]+100), int(diffroots[len(diffroots)-2]-diffroots[1]+201))
        #TODO: to end work with long table and algorithm with step
        dct = {}
        for i in xspace:
            dct[i] = sign(f(i))
        self.tableWidget.setColumnCount(2)
        rowCount = self.tableWidget.rowCount()
        self.tableWidget.insertRow(rowCount)
        self.tableWidget.setItem(rowCount, 0, QTableWidgetItem("x"))
        self.tableWidget.setItem(rowCount, 1, QTableWidgetItem("Sign f(x)"))
        keylist = []
        keylist = dct.keys()
        for key in sorted(keylist):
            rowCount = self.tableWidget.rowCount()
            self.tableWidget.insertRow(rowCount)
            self.tableWidget.setItem(rowCount, 0, QTableWidgetItem("%f" %key))
            self.tableWidget.setItem(rowCount, 1, QTableWidgetItem(dct[key]))

        self.derEdit.setText(str(diff))

        intervals = ''
        keylist = sorted(keylist)
        for i in range(len(keylist)-1):
            if (dct[keylist[i]] == '-' and dct[keylist[i+1]] == '+') or (dct[keylist[i]] == '+' and dct[keylist[i+1]] == '-'):
                intervals =( "%s%s" %(intervals, makeinterval(keylist[i], keylist[i+1], f)))
            elif (dct[keylist[i]] == '0'):
                intervals = ('%s{%f} and' % (intervals, keylist[i]))

        self.rootIntervalEdit.setText(intervals)









    def setupUi(self, MainWindow):
        super(MyMainWindow, self).setupUi(MainWindow)
        self.plotW = PlotWidget(self.tab_2)
        self.gridLayout_2.addWidget(self.plotW)
        self.GraphicalButton.clicked.connect(self.graphicalButtonClicked)
        self.analyticalButton.clicked.connect(self.analyticalButtonClicked)
        self.CnBW = CnBW()
        self.CnBW.setupUi(self.tab_4)
        self.NewtoneW = NewtoneWidget()
        self.NewtoneW.setupUi(self.tab_5)
        self.SInRW = SInRWidget()
        self.SInRW.setupUi(self.tab_6)