Mantid
Loading...
Searching...
No Matches
GausDecay.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(GausDecay)
23
24void GausDecay::init() {
25 declareParameter("A", 10.0, "Amplitude at time 0");
26 declareParameter("Sigma", 0.2, "Decay rate");
27}
28
29void GausDecay::function1D(double *out, const double *xValues, const size_t nData) const {
30 const double A = getParameter("A");
31 const double G = getParameter("Sigma");
32
33 for (size_t i = 0; i < nData; i++) {
34 double x = xValues[i];
35 out[i] = A * exp(-G * G * x * x);
36 }
37}
38
39void GausDecay::functionDeriv1D(Jacobian *out, const double *xValues, const size_t nData) {
40 const double A = getParameter("A");
41 const double G = getParameter("Sigma");
42
43 for (size_t i = 0; i < nData; i++) {
44 double x = xValues[i];
45 double g = exp(-G * G * x * x);
46 out->set(i, 0, g);
47 out->set(i, 1, -2 * G * x * x * A * g);
48 }
49}
50
51void GausDecay::setActiveParameter(size_t i, double value) {
52 size_t j = i;
53
54 if (parameterName(j) == "Sigma")
55 setParameter(j, fabs(value), false); // Make sigma positive
56 else
57 setParameter(j, value, false);
58}
59
60} // namespace Mantid::CurveFitting::Functions
double value
The value of the point.
Definition: FitMW.cpp:51
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
#define fabs(x)
Definition: Matrix.cpp:22
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.
void setParameter(size_t, const double &value, bool explicitlySet=true) override
Set i-th parameter.
std::string parameterName(size_t i) const override
Returns the name of parameter i.
double getParameter(size_t i) const override
Get i-th parameter.
Provide gaussian decay function: A*exp(-(sigma.x)^2))
Definition: GausDecay.h:26
void setActiveParameter(size_t i, double value) override
Set new value of i-th active parameter.
Definition: GausDecay.cpp:51
void functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) override
Derivatives of function with respect to active parameters.
Definition: GausDecay.cpp:39
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.
Definition: GausDecay.cpp:29