Mantid
Loading...
Searching...
No Matches
ProductLinearExp.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
17using namespace Kernel;
18
19using namespace API;
20
21DECLARE_FUNCTION(ProductLinearExp)
22
23//----------------------------------------------------------------------------------------------
27 declareParameter("A0", 1.0, "Coefficient for constant term");
28 declareParameter("A1", 1.0, "Coefficient for linear term");
29 declareParameter("Height", 1.0, "Height");
30 declareParameter("Lifetime", 1.0, "Lifetime");
31}
32
39void ProductLinearExp::functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) {
40 const double A0 = getParameter("A0");
41 const double A1 = getParameter("A1");
42 const double Height = getParameter("Height");
43 const double Lifetime = getParameter("Lifetime");
44
45 for (size_t i = 0; i < nData; i++) {
46 double x = xValues[i];
47 double expComponent = Height * std::exp(-x / Lifetime);
48 double linearComponent = (A1 * x) + A0;
49
50 out->set(i, 0, A1 * x * expComponent);
51 out->set(i, 1, (x + A0) * expComponent);
52 out->set(i, 2, linearComponent * expComponent / Height);
53 out->set(i, 3, linearComponent * expComponent * x / (Lifetime * Lifetime));
54 }
55}
56
63void ProductLinearExp::function1D(double *out, const double *xValues, const size_t nData) const {
64 const double A0 = getParameter("A0");
65 const double A1 = getParameter("A1");
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] = ((A1 * xValues[i]) + A0) * 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.
ProductLinearExp : Function that evauates the product of an exponential and linear function.
void functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) override
Calculate the 1D function derivatives.
void function1D(double *out, const double *xValues, const size_t nData) const override
Evaluate the 1D function.