Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rughinnit committed Oct 22, 2024
1 parent 9fb9e51 commit 54281c4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
21 changes: 16 additions & 5 deletions metnum_uts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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));
}
Expand All @@ -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);
Expand Down Expand Up @@ -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");
}
}
}
17 changes: 12 additions & 5 deletions metnum_uts.ui
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="5">
<item row="0" column="0" colspan="6">
<widget class="QComboBox" name="comboBox"/>
</item>
<item row="1" column="0">
Expand Down Expand Up @@ -56,22 +56,29 @@
</widget>
</item>
<item row="1" column="4">
<widget class="QLineEdit" name="MaxIter">
<property name="placeholderText">
<string>Maximum Iteration (Hati - hati CPU Anda)</string>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QLineEdit" name="Error">
<property name="text">
<string>0.0001</string>
<string>0.00001</string>
</property>
<property name="placeholderText">
<string>Insert Error</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="5">
<item row="2" column="0" colspan="6">
<widget class="QPlainTextEdit" name="plainTextEdit"/>
</item>
<item row="3" column="0" colspan="5">
<item row="3" column="0" colspan="6">
<widget class="QLabel" name="label">
<property name="text">
<string>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.</string>
<string>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</string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down

0 comments on commit 54281c4

Please sign in to comment.