Mantid
Loading...
Searching...
No Matches
ExpDecay.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#include <cmath>
13
15
16using namespace CurveFitting;
17
18using namespace Kernel;
19
20using namespace API;
21
22DECLARE_FUNCTION(ExpDecay)
23
25 declareParameter("Height", 1.0, "Height at time 0");
26 declareParameter("Lifetime", 1.0, "Lifetime of the process");
27}
28
29void ExpDecay::function1D(double *out, const double *xValues, const size_t nData) const {
30 const double h = getParameter("Height");
31 const double t = getParameter("Lifetime");
32
33 for (size_t i = 0; i < nData; i++) {
34 out[i] = h * exp(-(xValues[i]) / t);
35 }
36}
37
38void ExpDecay::functionDeriv1D(Jacobian *out, const double *xValues, const size_t nData) {
39 const double h = getParameter("Height");
40 const double t = getParameter("Lifetime");
41
42 for (size_t i = 0; i < nData; i++) {
43 double x = xValues[i];
44 double e = exp(-x / t);
45 out->set(i, 0, e);
46 out->set(i, 1, h * e * x / t / t);
47 }
48}
49
50} // 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 exponential decay function: h*exp(-(x-c)/t)
Definition: ExpDecay.h:25
void functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) override
Derivatives of function with respect to active parameters.
Definition: ExpDecay.cpp:38
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.
Definition: ExpDecay.cpp:29