From 225ff71859db0d735a910cda2e78de6b792dbf8d Mon Sep 17 00:00:00 2001 From: yuntang <123@qq.com> Date: Tue, 6 May 2025 17:26:23 +0800 Subject: [PATCH] 2025-05-06T17:26:22 --- experiment_data/sample_data/~$锡.xlsx | Bin 165 -> 0 bytes src/main.cpp | 1 - src/ui/coefficientselectionform.cpp | 213 +++++++++++++++++--------- src/ui/coefficientselectionform.h | 3 + src/ui/enthalpydatacorrectionform.cpp | 128 +++++++++------- src/ui/enthalpydatacorrectionform.h | 4 +- src/ui/enthalpydatacorrectionform.ui | 36 ++--- 7 files changed, 239 insertions(+), 146 deletions(-) delete mode 100644 experiment_data/sample_data/~$锡.xlsx diff --git a/experiment_data/sample_data/~$锡.xlsx b/experiment_data/sample_data/~$锡.xlsx deleted file mode 100644 index d4a5841882f71e1e9259c5c320e2b84832515279..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 165 ZcmZQhOiETD9WXN_G9)o1Gbqpn0s!Zc4-)_Y diff --git a/src/main.cpp b/src/main.cpp index a51273b..9ddeee0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,7 +51,6 @@ int main(int argc, char *argv[]) // a.setWindowIcon(QIcon(":/images/logo.png")); - #if 1 MainWindow w; w.setWindowTitle("Analysis Tool"); diff --git a/src/ui/coefficientselectionform.cpp b/src/ui/coefficientselectionform.cpp index 4f24051..68b064a 100644 --- a/src/ui/coefficientselectionform.cpp +++ b/src/ui/coefficientselectionform.cpp @@ -64,12 +64,20 @@ void CoefficientSelectionForm::on_pushButtonConfirm_clicked() for (const QJsonValue &value : jsonArray) { QJsonObject jsonObj = value.toObject(); - xVtr< max_val) { + max_val = std::fabs(A[j][i]); + max_row = j; + } + } + + // 交换行 + if (max_row != i) { + for (int k = 0; k < 3; ++k) { + std::swap(A[i][k], A[max_row][k]); + } + std::swap(b[i], b[max_row]); + } + + // 消元 + for (int j = i + 1; j < 3; ++j) { + double factor = A[j][i] / A[i][i]; + for (int k = i; k < 3; ++k) { + A[j][k] -= factor * A[i][k]; + } + b[j] -= factor * b[i]; + } + } + + // 回代求解 + coeff[2] = b[2] / A[2][2]; + for (int i = 1; i >= 0; --i) { + double sum = 0.0; + for (int j = i + 1; j < 3; ++j) { + sum += A[i][j] * coeff[j]; + } + coeff[i] = (b[i] - sum) / A[i][i]; + } +} void CoefficientSelectionForm::on_pushButtonSelectFile_clicked() { QString filePath = QFileDialog::getOpenFileName( @@ -125,7 +199,6 @@ void CoefficientSelectionForm::on_pushButtonSelectFile_clicked() // ui->labelFilePath->setText(filePath); ui->textEditFileContent->setText(_jsonStr); - } void CoefficientSelectionForm::on_radioButtonSinglePointCoefficient_toggled(bool checked) @@ -172,79 +245,79 @@ void CoefficientSelectionForm::cubicLeastSquaresFit( double x[], double y[], int n, double coeff[]) { int i, j, k; - double atemp[3] = {0}; // 存储x^0, x^1, x^2的和 - double b[3] = {0}; // 右侧向量 + double atemp[3] = {0}; // 存储x^0, x^1, x^2的和 + double b[3] = {0}; // 右侧向量 - // 计算各次幂的和 - for (i = 0; i < n; i++) { - double xi = x[i]; - double xi_pow2 = xi * xi; // x^2 + // 计算各次幂的和 + for (i = 0; i < n; i++) { + double xi = x[i]; + double xi_pow2 = xi * xi; // x^2 - // 累加atemp[0]到atemp[2] - atemp[0] += 1; // x^0的和等于数据点个数 - atemp[1] += xi; - atemp[2] += xi_pow2; + // 累加atemp[0]到atemp[2] + atemp[0] += 1; // x^0的和等于数据点个数 + atemp[1] += xi; + atemp[2] += xi_pow2; - // 计算右侧向量b - double yi = y[i]; - b[0] += yi; - b[1] += yi * xi; - b[2] += yi * xi_pow2; - } + // 计算右侧向量b + double yi = y[i]; + b[0] += yi; + b[1] += yi * xi; + b[2] += yi * xi_pow2; + } - // 构建法方程矩阵 - double a[3][3]; - a[0][0] = atemp[0]; - a[0][1] = atemp[1]; - a[0][2] = atemp[2]; - a[1][0] = atemp[1]; - a[1][1] = atemp[2]; - a[1][2] = 0; - a[2][0] = atemp[2]; - a[2][1] = 0; - a[2][2] = 0; + // 构建法方程矩阵 + double a[3][3]; + a[0][0] = atemp[0]; + a[0][1] = atemp[1]; + a[0][2] = atemp[2]; + a[1][0] = atemp[1]; + a[1][1] = atemp[2]; + a[1][2] = 0; + a[2][0] = atemp[2]; + a[2][1] = 0; + a[2][2] = 0; - // 高斯列主元消元法 - for (k = 0; k < 2; k++) { // 消去第k列 - // 寻找主元行 - int max_row = k; - double max_val = fabs(a[k][k]); - for (i = k + 1; i < 3; i++) { - if (fabs(a[i][k]) > max_val) { - max_val = fabs(a[i][k]); - max_row = i; - } - } + // 高斯列主元消元法 + for (k = 0; k < 2; k++) { // 消去第k列 + // 寻找主元行 + int max_row = k; + double max_val = fabs(a[k][k]); + for (i = k + 1; i < 3; i++) { + if (fabs(a[i][k]) > max_val) { + max_val = fabs(a[i][k]); + max_row = i; + } + } - // 交换行 - if (max_row != k) { - for (j = k; j < 3; j++) { - double temp = a[k][j]; - a[k][j] = a[max_row][j]; - a[max_row][j] = temp; - } - double temp_b = b[k]; - b[k] = b[max_row]; - b[max_row] = temp_b; - } + // 交换行 + if (max_row != k) { + for (j = k; j < 3; j++) { + double temp = a[k][j]; + a[k][j] = a[max_row][j]; + a[max_row][j] = temp; + } + double temp_b = b[k]; + b[k] = b[max_row]; + b[max_row] = temp_b; + } - // 消元 - for (i = k + 1; i < 3; i++) { - double factor = a[i][k] / a[k][k]; - for (j = k; j < 3; j++) { - a[i][j] -= factor * a[k][j]; - } - b[i] -= factor * b[k]; - } - } + // 消元 + for (i = k + 1; i < 3; i++) { + double factor = a[i][k] / a[k][k]; + for (j = k; j < 3; j++) { + a[i][j] -= factor * a[k][j]; + } + b[i] -= factor * b[k]; + } + } - // 回代求解 - coeff[2] = b[2] / a[2][2]; - for (i = 1; i >= 0; i--) { - double sum = 0.0; - for (j = i + 1; j < 3; j++) { - sum += a[i][j] * coeff[j]; - } - coeff[i] = (b[i] - sum) / a[i][i]; - } + // 回代求解 + coeff[2] = b[2] / a[2][2]; + for (i = 1; i >= 0; i--) { + double sum = 0.0; + for (j = i + 1; j < 3; j++) { + sum += a[i][j] * coeff[j]; + } + coeff[i] = (b[i] - sum) / a[i][i]; + } } diff --git a/src/ui/coefficientselectionform.h b/src/ui/coefficientselectionform.h index c5ae511..a56dad1 100644 --- a/src/ui/coefficientselectionform.h +++ b/src/ui/coefficientselectionform.h @@ -26,7 +26,10 @@ private slots: void on_pushButtonConfirm_clicked(); void on_pushButtonExit_clicked(); private: + // 立方拟合 void cubicLeastSquaresFit(double x[], double y[], int n, double coeff[4]); + // 平方拟合 + void quadraticLeastSquaresFit(double x[], double y[], int n, double coeff[]); QString _jsonStr; Ui::CoefficientSelectionForm *ui; diff --git a/src/ui/enthalpydatacorrectionform.cpp b/src/ui/enthalpydatacorrectionform.cpp index 9cc6063..5b6e9b4 100644 --- a/src/ui/enthalpydatacorrectionform.cpp +++ b/src/ui/enthalpydatacorrectionform.cpp @@ -31,112 +31,130 @@ EnthalpyDataCorrectionForm::~EnthalpyDataCorrectionForm() void EnthalpyDataCorrectionForm::on_pushButtonSave_clicked() { if(ui->checkBoxC6H12->isChecked()){ - float theory = ui->lineEditTheoryC6H12->text().toFloat(); - float measure = ui->lineEditMeasC6H12->text().toFloat(); + double temperature = ui->labelTempC6H12->text().toDouble(); + double theory = ui->lineEditTheoryC6H12->text().toDouble(); + double measure = ui->lineEditMeasC6H12->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxHg->isChecked()){ - float theory = ui->lineEditTheoryHg->text().toFloat(); - float measure = ui->lineEditMeasHg->text().toFloat(); + double temperature = ui->labelTempHg->text().toDouble(); + double theory = ui->lineEditTheoryHg->text().toDouble(); + double measure = ui->lineEditMeasHg->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxC6H5COOH->isChecked()){ - float theory = ui->lineEditTheoryC6H5COOH->text().toFloat(); - float measure = ui->lineEditMeasC6H5COOH->text().toFloat(); + double temperature = ui->labelTempC6H5COOH->text().toDouble(); + double theory = ui->lineEditTheoryC6H5COOH->text().toDouble(); + double measure = ui->lineEditMeasC6H5COOH->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxIn->isChecked()){ - float theory = ui->lineEditTheoryIn->text().toFloat(); - float measure = ui->lineEditMeasIn->text().toFloat(); + double temperature = ui->labelTempIn->text().toDouble(); + double theory = ui->lineEditTheoryIn->text().toDouble(); + double measure = ui->lineEditMeasIn->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxSn->isChecked()){ - float theory = ui->lineEditTheorySn->text().toFloat(); - float measure = ui->lineEditMeasSn->text().toFloat(); + double temperature = ui->labelTempSn->text().toDouble(); + double theory = ui->lineEditTheorySn->text().toDouble(); + double measure = ui->lineEditMeasSn->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxBi->isChecked()){ - float theory = ui->lineEditTheoryBi->text().toFloat(); - float measure = ui->lineEditMeasBi->text().toFloat(); + double temperature = ui->labelTempBi->text().toDouble(); + double theory = ui->lineEditTheoryBi->text().toDouble(); + double measure = ui->lineEditMeasBi->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxKC1O3->isChecked()){ - float theory = ui->lineEditTheoryKC1O3->text().toFloat(); - float measure = ui->lineEditMeasKC103->text().toFloat(); + double temperature = ui->labelTempKC1O3->text().toDouble(); + double theory = ui->lineEditTheoryKC1O3->text().toDouble(); + double measure = ui->lineEditMeasKC103->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxPb->isChecked()){ - float theory = ui->lineEditTheoryPb->text().toFloat(); - float measure = ui->lineEditMeasPb->text().toFloat(); + double temperature = ui->labelTempPb->text().toDouble(); + double theory = ui->lineEditTheoryPb->text().toDouble(); + double measure = ui->lineEditMeasPb->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxKNO3->isChecked()){ - float theory = ui->lineEditTheoryKNO3->text().toFloat(); - float measure = ui->lineEditMeasKNO3->text().toFloat(); + double temperature = ui->labelTempKNO3->text().toDouble(); + double theory = ui->lineEditTheoryKNO3->text().toDouble(); + double measure = ui->lineEditMeasKNO3->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxZn->isChecked()){ - float theory = ui->lineEditTheoryZn->text().toFloat(); - float measure = ui->lineEditMeasZn->text().toFloat(); + double temperature = ui->labelTempZn->text().toDouble(); + double theory = ui->lineEditTheoryZn->text().toDouble(); + double measure = ui->lineEditMeasZn->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxAg2SO4->isChecked()){ - float theory = ui->lineEditTheoryAg2SO4->text().toFloat(); - float measure = ui->lineEditMeasAg2SO4->text().toFloat(); + double temperature = ui->labelTempAg2SO4->text().toDouble(); + double theory = ui->lineEditTheoryAg2SO4->text().toDouble(); + double measure = ui->lineEditMeasAg2SO4->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxCsCl->isChecked()){ - float theory = ui->lineEditTheoryCsC1->text().toFloat(); - float measure = ui->lineEditMeasCsCl->text().toFloat(); + double temperature = ui->labelTempCsC1->text().toDouble(); + double theory = ui->lineEditTheoryCsC1->text().toDouble(); + double measure = ui->lineEditMeasCsCl->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxSiO2->isChecked()){ - float theory = ui->lineEditTheorySiO2->text().toFloat(); - float measure = ui->lineEditMeasSiO2->text().toFloat(); + double temperature = ui->labelTempSiO2->text().toDouble(); + double theory = ui->lineEditTheorySiO2->text().toDouble(); + double measure = ui->lineEditMeasSiO2->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxK2SO4->isChecked()){ - float theory = ui->lineEditTheoryK2SO4->text().toFloat(); - float measure = ui->lineEditMeasK2SO4->text().toFloat(); + double temperature = ui->labelTempK2SO4->text().toDouble(); + double theory = ui->lineEditTheoryK2SO4->text().toDouble(); + double measure = ui->lineEditMeasK2SO4->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxK2CrO4->isChecked()){ - float theory = ui->lineEditTheoryK2CrO4->text().toFloat(); - float measure = ui->lineEditMeasK2CrO4->text().toFloat(); + double temperature = ui->labelTempK2CrO4->text().toDouble(); + double theory = ui->lineEditTheoryK2CrO4->text().toDouble(); + double measure = ui->lineEditMeasK2CrO4->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxBaCO3->isChecked()){ - float theory = ui->lineEditTheoryBaCO3->text().toFloat(); - float measure = ui->lineEditMeasBaCO3->text().toFloat(); + double temperature = ui->labelTempBaCO3->text().toDouble(); + double theory = ui->lineEditTheoryBaCO3->text().toDouble(); + double measure = ui->lineEditMeasBaCO3->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxAg->isChecked()){ - float theory = ui->lineEditTheoryAg->text().toFloat(); - float measure = ui->lineEditMeasAg->text().toFloat(); + double temperature = ui->labelTempAg->text().toDouble(); + double theory = ui->lineEditTheoryAg->text().toDouble(); + double measure = ui->lineEditMeasAg->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } if(ui->checkBoxCu->isChecked()){ - float theory = ui->lineEditTheoryCu->text().toFloat(); - float measure = ui->lineEditMeasCu->text().toFloat(); + double temperature = ui->labelTempCu->text().toDouble(); + double theory = ui->lineEditTheoryCu->text().toDouble(); + double measure = ui->lineEditMeasCu->text().toDouble(); - _theoryDataVtr.push_back({theory,theory/measure}); + _theoryDataVtr.push_back({temperature,theory/measure}); } // saveJson(); @@ -153,7 +171,7 @@ void EnthalpyDataCorrectionForm::saveJson() QJsonArray jsonArray; for (const TheoryData &data : _theoryDataVtr) { QJsonObject jsonObj; - jsonObj["theory"] = data.theory; + jsonObj["temperature"] = data.temperature; jsonObj["rate"] = data.rate; jsonArray.append(jsonObj); } diff --git a/src/ui/enthalpydatacorrectionform.h b/src/ui/enthalpydatacorrectionform.h index 9e93f25..2841e82 100644 --- a/src/ui/enthalpydatacorrectionform.h +++ b/src/ui/enthalpydatacorrectionform.h @@ -23,8 +23,8 @@ private: void saveJson(); private: struct TheoryData{ - float theory; - float rate; + double temperature; + double rate; }; QVector _theoryDataVtr; diff --git a/src/ui/enthalpydatacorrectionform.ui b/src/ui/enthalpydatacorrectionform.ui index 0a26eb2..6b0ed81 100644 --- a/src/ui/enthalpydatacorrectionform.ui +++ b/src/ui/enthalpydatacorrectionform.ui @@ -59,7 +59,7 @@ - + 573.0 @@ -69,7 +69,7 @@ - + 299.5 @@ -93,7 +93,7 @@ - + 476.0 @@ -114,7 +114,7 @@ - + 327.4 @@ -127,7 +127,7 @@ - + 430.0 @@ -157,7 +157,7 @@ - + 665.0 @@ -205,7 +205,7 @@ - + 231.9 @@ -219,7 +219,7 @@ - + 122.1 @@ -246,7 +246,7 @@ - + 810.0 @@ -292,7 +292,7 @@ - + 583.0 @@ -306,7 +306,7 @@ - + 334.0 @@ -323,7 +323,7 @@ - + -86.0 @@ -377,7 +377,7 @@ - + 961.8 @@ -407,7 +407,7 @@ - + 271.4 @@ -421,7 +421,7 @@ - + 1083.0 @@ -452,7 +452,7 @@ - + 419.5 @@ -506,7 +506,7 @@ - + -38.8 @@ -553,7 +553,7 @@ - + 156.6