Polynomial.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2004 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/MEAL/MEAL/Polynomial.h
10 
11 #ifndef __Polynomial_H
12 #define __Polynomial_H
13 
14 #include "MEAL/Univariate.h"
15 #include "MEAL/Scalar.h"
16 #include "MEAL/Parameters.h"
17 
18 namespace MEAL {
19 
21  class Polynomial : public Univariate<Scalar> {
22 
23  public:
24 
26  Polynomial (unsigned ncoef = 0);
27 
29  Polynomial (const Polynomial&);
30 
33 
35  Polynomial* clone () const;
36 
38  void resize (unsigned ncoef);
39 
41  template<class T>
42  Polynomial (const std::vector<T>& coefs) : parameters (this, coefs.size())
43  {
44  init ();
45  for (unsigned ic=0; ic < coefs.size(); ic++)
46  set_param (ic, coefs[ic]);
47  }
48 
50  void set_abscissa_offset(double x0)
51  { x_0 = x0; }
52 
53  // ///////////////////////////////////////////////////////////////////
54  //
55  // Function implementation
56  //
57  // ///////////////////////////////////////////////////////////////////
58 
60  std::string get_name () const;
61 
63  void parse (const std::string& text);
64 
65  protected:
66 
68  void calculate (double& x, std::vector<double>* grad=0);
69 
71  void print_parameters (std::string& text, const std::string& sep) const;
72 
73  private:
74 
76  double x_0;
77 
79  Parameters parameters;
80 
82  void init ();
83 
84  };
85 
86 }
87 
88 #endif
Abstract base class implements parameter storage and access.
Definition: Parameters.h:28
void set_param(unsigned index, double value)
Set the value of the specified parameter.
Definition: Function.h:131
void print_parameters(std::string &text, const std::string &sep) const
Print the values of model parameters and fit flags to a string.
Definition: Polynomial.C:109
virtual void print_parameters(std::string &text, const std::string &separator) const
Prints the values of model parameters and fit flags to a string.
Definition: Function_print.C:22
void calculate(double &x, std::vector< double > *grad=0)
Return the value (and gradient, if requested) of the function.
Definition: Polynomial.C:117
void parse(const std::string &text)
Parses the values of model parameters and fit flags from a string.
Definition: Polynomial.C:68
Polynomial(unsigned ncoef=0)
Default constructor.
Definition: Polynomial.C:23
std::string get_name() const
Return the name of the class.
Definition: Polynomial.C:63
Namespace in which all modeling and calibration related code is declared.
Definition: ExampleComplex2.h:16
void resize(unsigned ncoef)
Resize.
Definition: Polynomial.C:54
void set_abscissa_offset(double x0)
Setter.
Definition: Polynomial.h:60
virtual void parse(const std::string &text)
Parses the values of model parameters and fit flags from a string.
Definition: Function_parse.C:16
Polynomial function with an arbitrary number of coefficients.
Definition: Polynomial.h:26
Polynomial * clone() const
Clone operator.
Definition: Polynomial.C:49
Polynomial & operator=(const Polynomial &)
Assignment operator.
Definition: Polynomial.C:37
virtual void copy(const Function *model)
Does the work for operator =.
Definition: Function.C:58

Generated using doxygen 1.8.17