From 54281c41b73da9b59bc7975057c7c089d0f6a2f2 Mon Sep 17 00:00:00 2001 From: sirrugh Date: Tue, 22 Oct 2024 21:13:34 +0700 Subject: [PATCH] update --- metnum_uts.cpp | 21 ++++++++++++++++----- metnum_uts.ui | 17 ++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/metnum_uts.cpp b/metnum_uts.cpp index 83d153d..7305e46 100644 --- a/metnum_uts.cpp +++ b/metnum_uts.cpp @@ -59,6 +59,7 @@ double metnum_uts::evaluateDerivative(const QString& functionString, double x) { void metnum_uts::on_pushButton_clicked() { ui->plainTextEdit->clear(); + QString MaxIter = ui->MaxIter->text(); QString selectedmetode = ui->comboBox->currentText(); QString functionString = ui->Function->text(); @@ -101,7 +102,12 @@ void metnum_uts::on_pushButton_clicked() double c = a; int iteration = 0; - const int MAX_ITERATIONS = 1000; + const int MAX_ITERATIONS = MaxIter.toInt(&ok); + + if (!ok) { + ui->plainTextEdit->appendPlainText("Max Iterations value is invalid"); + return; + } while (iteration < MAX_ITERATIONS) { c = (a * fb - b * fa) / (fb - fa); @@ -125,7 +131,7 @@ void metnum_uts::on_pushButton_clicked() } if (iteration == MAX_ITERATIONS) { - ui->plainTextEdit->appendPlainText("Max iteration"); + ui->plainTextEdit->appendPlainText("Max iteration limit sudah tercapai"); } else { ui->plainTextEdit->appendPlainText(QString("Root found at: %1").arg(c, 0, 'f', 6)); } @@ -146,7 +152,12 @@ void metnum_uts::on_pushButton_clicked() double x = x0; int iteration = 0; - const int MAX_ITERATIONS = 1000; + const int MAX_ITERATIONS = MaxIter.toInt(&ok); + + if (!ok) { + ui->plainTextEdit->appendPlainText("Max Iterations value is invalid"); + return; + } while (iteration < MAX_ITERATIONS) { double fx = evaluateFunction(functionString, x); @@ -177,8 +188,8 @@ void metnum_uts::on_pushButton_clicked() iteration++; } - if (iteration >= MAX_ITERATIONS) { - ui->plainTextEdit->appendPlainText("Maximum iterations reached"); + if (iteration == MAX_ITERATIONS) { + ui->plainTextEdit->appendPlainText("Max iteration limit sudah tercapai"); } } } diff --git a/metnum_uts.ui b/metnum_uts.ui index e7a7618..a0e4852 100644 --- a/metnum_uts.ui +++ b/metnum_uts.ui @@ -15,7 +15,7 @@ - + @@ -56,22 +56,29 @@ + + + Maximum Iteration (Hati - hati CPU Anda) + + + + - 0.0001 + 0.00001 Insert Error - + - + - Tips: Tidak bisa menggunakan pangkat (^) semua harus memakai perkalian (*). Untuk menggunakan Sin, Cos, Tan, dan kawan-kawannya bisa menggunakan sin(). Maximum Iterasi adalah 1000. Untuk Metode Newton Raphson, gunakan A untuk initial guess. + Tips: Tidak bisa menggunakan pangkat (^) semua harus memakai perkalian (*). Untuk menggunakan Sin, Cos, Tan, dan kawan-kawannya bisa menggunakan sin(). Untuk Metode Newton Raphson, gunakan A untuk initial guess. Normal Maximum Iteration=1000 true