Mantid
Loading...
Searching...
No Matches
ProductQuadraticExp.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 +
12
14
15using namespace CurveFitting;
16
17DECLARE_FUNCTION(ProductQuadraticExp)
18
19//----------------------------------------------------------------------------------------------
23 declareParameter("A0", 0.0, "Coefficient for constant term");
24 declareParameter("A1", 0.0, "Coefficient for linear term");
25 declareParameter("A2", 0.0, "Coefficient for quadratic term");
26 declareParameter("Height", 1.0, "Height");
27 declareParameter("Lifetime", 1.0, "Lifetime");
28}
29
36void ProductQuadraticExp::functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) {
37 const double A0 = getParameter("A0");
38 const double A1 = getParameter("A1");
39 const double A2 = getParameter("A2");
40 const double Height = getParameter("Height");
41 const double Lifetime = getParameter("Lifetime");
42
43 for (size_t i = 0; i < nData; i++) {
44 double x = xValues[i];
45 double expComponent = Height * std::exp(-x / Lifetime);
46 double linearComponent = (A1 * x) + A0;
47
48 out->set(i, 0, ((A2 * x * x) + (A1 * x)) * expComponent);
49 out->set(i, 1, ((A2 * x * x) + x + A0) * expComponent);
50 out->set(i, 2, ((x * x) + (A1 * x) + A0) * expComponent);
51 out->set(i, 3, linearComponent * expComponent / Height);
52 out->set(i, 4, linearComponent * expComponent * x / (Lifetime * Lifetime));
53 }
54}
55
62void ProductQuadraticExp::function1D(double *out, const double *xValues, const size_t nData) const {
63 const double A0 = getParameter("A0");
64 const double A1 = getParameter("A1");
65 const double A2 = getParameter("A2");
66 const double Height = getParameter("Height");
67 const double Lifetime = getParameter("Lifetime");
68
69 for (size_t i = 0; i < nData; ++i) {
70 out[i] = (A0 + (A1 * xValues[i]) + (A2 * xValues[i] * xValues[i])) * Height * std::exp(-xValues[i] / Lifetime);
71 }
72}
73
74} // 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.
ProductQuadraticExp : Function that evauates the product of an exponential and quadratic function.
void function1D(double *out, const double *xValues, const size_t nData) const override
Evaluate the 1D function.
void functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) override
Calculate the 1D function derivatives.