QtiPlot  0.9.8.2
PolynomialFit.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : PolynomialFit.h
3  Project : QtiPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2006 by Ion Vasilief
6  Email (use @ for *) : ion_vasilief*yahoo.fr
7  Description : Polynomial Fit and Linear Fit classes
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
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. *
17  * *
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. *
22  * *
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 *
27  * *
28  ***************************************************************************/
29 #ifndef POLYNOMIALFIT_H
30 #define POLYNOMIALFIT_H
31 
32 #include "Fit.h"
33 
34 class PolynomialFit : public Fit
35 {
36  Q_OBJECT
37 
38  public:
39  PolynomialFit(ApplicationWindow *parent, QwtPlotCurve *c, int order = 2, bool legend = false);
40  PolynomialFit(ApplicationWindow *parent, QwtPlotCurve *c, double start, double end, int order = 2, bool legend = false);
41  PolynomialFit(ApplicationWindow *parent, Graph *g, int order = 2, bool legend = false);
42  PolynomialFit(ApplicationWindow *parent, Graph *g, QString& curveTitle, int order = 2, bool legend = false);
43  PolynomialFit(ApplicationWindow *parent, Graph *g, QString& curveTitle, double start, double end, int order = 2, bool legend = false);
44  PolynomialFit(ApplicationWindow *parent, Table *t, const QString& xCol, const QString& yCol, int startRow = 1, int endRow = -1, int order = 2, bool legend = false);
45 
46  virtual QString legendInfo();
47  void fit();
48 
49  int order(){return d_order;};
50  void setOrder(int order);
51 
52  static QString generateFormula(int order);
53  static QStringList generateParameterList(int order);
54 
55  virtual double eval(double *par, double x);
56 
57  private:
58  void init();
59  void calculateFitCurveData(double *X, double *Y);
60 
61  int d_order;
63 };
64 
65 class LinearFit : public Fit
66 {
67  Q_OBJECT
68 
69  public:
70  LinearFit(ApplicationWindow *parent, Graph *g);
71  LinearFit(ApplicationWindow *parent, QwtPlotCurve *c);
72  LinearFit(ApplicationWindow *parent, QwtPlotCurve *c, double start, double end);
73  LinearFit(ApplicationWindow *parent, Graph *g, const QString& curveTitle);
74  LinearFit(ApplicationWindow *parent, Graph *g, const QString& curveTitle, double start, double end);
75  LinearFit(ApplicationWindow *parent, Table *t, const QString& xCol, const QString& yCol, int startRow = 1, int endRow = -1);
76 
77  void fit();
78  virtual double eval(double *par, double x){return par[0] + par[1]*x;};
79 
80  private:
81  void init();
82  void calculateFitCurveData(double *X, double *Y);
83 };
84 
85 class LinearSlopeFit : public Fit
86 {
87  Q_OBJECT
88 
89  public:
91  LinearSlopeFit(ApplicationWindow *parent, Graph *g, const QString& curveTitle);
92  LinearSlopeFit(ApplicationWindow *parent, Graph *g, const QString& curveTitle, double start, double end);
93  LinearSlopeFit(ApplicationWindow *parent, Table *t, const QString& xCol, const QString& yCol, int startRow = 1, int endRow = -1);
94 
95  void fit();
96  virtual double eval(double *par, double x){return par[0]*x;};
97 
98  private:
99  void init();
100  void calculateFitCurveData(double *X, double *Y);
101 };
102 #endif