36 lines
1 KiB
C++
36 lines
1 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include <QDebug>
|
|
#include <cmath>
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
|
ui->setupUi(this);
|
|
//设置TAB顺序
|
|
setTabOrder(ui->equal, ui->x0);
|
|
setTabOrder(ui->x0, ui->x1);
|
|
setTabOrder(ui->x1, ui->w0);
|
|
setTabOrder(ui->w0, ui->w1);
|
|
setTabOrder(ui->w1, ui->b);
|
|
setTabOrder(ui->b, ui->equal);
|
|
}
|
|
|
|
MainWindow::~MainWindow() { delete ui; }
|
|
|
|
void MainWindow::on_equal_clicked() {
|
|
double num = ui->x0->value() * ui->w0->value() +
|
|
ui->x1->value() * ui->w1->value() + ui->b->value();
|
|
|
|
qDebug() << num;
|
|
|
|
num = sigmoid(num);
|
|
|
|
ui->result->setText(QString::number(num, 'f', 16));
|
|
ui->list->addItem("f(" + QString::number(ui->x0->value(), 'f', 2) + "," +
|
|
QString::number(ui->x1->value(), 'f', 2) +
|
|
")=" + QString::number(num, 'f', 2));
|
|
}
|
|
|
|
double MainWindow::sigmoid(double x) { return 1 / (1 + exp(-x)); }
|
|
|
|
void MainWindow::on_action_triggered() { ui->list->clear(); }
|