Mantid
Loading...
Searching...
No Matches
Quadratic.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
12
14
15using namespace CurveFitting;
16
17using namespace Kernel;
18
19using namespace API;
20
21DECLARE_FUNCTION(Quadratic)
22
23
26void Quadratic::init() {
27 declareParameter("A0", 0.0, "coefficient for constant term");
28 declareParameter("A1", 0.0, "coefficient for linear term");
29 declareParameter("A2", 0.0, "coefficient for quadratic term");
30}
31
38void Quadratic::function1D(double *out, const double *xValues, const size_t nData) const {
39 const double a0 = getParameter("A0");
40 const double a1 = getParameter("A1");
41 const double a2 = getParameter("A2");
42
43 for (size_t i = 0; i < nData; i++) {
44 out[i] = a0 + a1 * xValues[i] + a2 * xValues[i] * xValues[i];
45 }
46}
47
54void Quadratic::functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) {
55 for (size_t i = 0; i < nData; i++) {
56 out->set(i, 0, 1);
57 out->set(i, 1, xValues[i]);
58 out->set(i, 2, xValues[i] * xValues[i]);
59 }
60}
61
62} // namespace Mantid::CurveFitting::Functions
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
virtual void set(size_t iY, size_t iP, double value)=0
Set a value to a Jacobian matrix element.
double getParameter(size_t i) const override
Get i-th parameter.
Provide quadratic function interface to IFunction.
Definition: Quadratic.h:31
void functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) override
Derivatives of function with respect to active parameters.
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.