1
/***************************************************************************
2
File : NonLinearFit.cpp
4
--------------------------------------------------------------------
5
Copyright : (C) 2006 by Ion Vasilief, Tilman Benkert
6
Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
7
Description : NonLinearFit class
9
***************************************************************************/
11
/***************************************************************************
13
* This program is free software; you can redistribute it and/or modify *
14
* it under the terms of the GNU General Public License as published by *
15
* the Free Software Foundation; either version 2 of the License, or *
16
* (at your option) any later version. *
18
* This program is distributed in the hope that it will be useful, *
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21
* GNU General Public License for more details. *
23
* You should have received a copy of the GNU General Public License *
24
* along with this program; if not, write to the Free Software *
25
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26
* Boston, MA 02110-1301 USA *
28
***************************************************************************/
29
#include "NonLinearFit.h"
33
#include <QMessageBox>
35
NonLinearFit::NonLinearFit(ApplicationWindow *parent, Graph *g)
41
NonLinearFit::NonLinearFit(ApplicationWindow *parent, Graph *g, const QString& curveTitle)
45
setDataFromCurve(curveTitle);
48
NonLinearFit::NonLinearFit(ApplicationWindow *parent, Graph *g, const QString& curveTitle, double start, double end)
52
setDataFromCurve(curveTitle, start, end);
55
void NonLinearFit::init()
57
setName(tr("NonLinear"));
58
d_formula = QString::null;
63
d_explanation = tr("Non-linear");
67
void NonLinearFit::setFormula(const QString& s)
72
void NonLinearFit::setParametersList(const QStringList& lst)
74
if ((int)lst.count() < 1)
76
QMessageBox::critical((ApplicationWindow *)parent(), tr("Fit Error"),
77
tr("You must provide a list containing at least one parameter for this type of fit. Operation aborted!"));
86
{//free previously allocated memory
87
gsl_vector_free(d_param_init);
88
gsl_matrix_free (covar);
92
d_p = (int)lst.count();
94
d_param_init = gsl_vector_alloc(d_p);
95
gsl_vector_set_all (d_param_init, 1.0);
97
covar = gsl_matrix_alloc (d_p, d_p);
98
d_results = new double[d_p];
100
for (int i=0; i<d_p; i++)
101
d_param_explain << "";
104
void NonLinearFit::calculateFitCurveData(double *par, double *X, double *Y)
106
for (int i=0; i<d_p; i++)
107
d_script->setDouble(par[i], d_param_names[i]);
109
if (d_gen_function) {
111
double step = (d_x[d_n-1]-X0)/(d_points-1);
112
for (int i=0; i<d_points; i++) {
114
d_script->setDouble(X[i], "x");
115
Y[i] = d_script->eval().toDouble();
118
for (int i=0; i<d_points; i++) {
120
d_script->setDouble(X[i], "x");
121
Y[i] = d_script->eval().toDouble();