24 for (
size_t i = 0; i < nData; ++i) {
25 double x = xValues[i];
31 out[i] = (A + B *
x) * pow(
x, 2);
34 out[i] = (A + B *
x) * pow(
x, 4);
37 throw std::runtime_error(
"Unknown attribute value.");
44 for (
size_t i = 0; i < nData; ++i) {
45 double x = xValues[i];
52 out->
set(i, 0, pow(
x, 2));
53 out->
set(i, 1, pow(
x, 3));
56 out->
set(i, 0, pow(
x, 4));
57 out->
set(i, 1, pow(
x, 5));
60 throw std::runtime_error(
"Unknown attribute value.");
66 auto multi = std::make_shared<Mantid::API::MultiDomainFunction>();
67 multi->addFunction(std::make_shared<MultiDomainFunctionTest_Function>());
68 multi->addFunction(std::make_shared<MultiDomainFunctionTest_Function>());
69 multi->addFunction(std::make_shared<MultiDomainFunctionTest_Function>());
71 multi->getFunction(0)->setParameter(
"A", 0);
72 multi->getFunction(0)->setParameter(
"B", 0);
74 multi->getFunction(1)->setParameter(
"A", 0);
75 multi->getFunction(1)->setParameter(
"B", 0);
77 multi->getFunction(2)->setParameter(
"A", 0);
78 multi->getFunction(2)->setParameter(
"B", 0);
80 multi->clearDomainIndices();
81 multi->setDomainIndices(1, {0, 1});
82 multi->setDomainIndices(2, {0, 2});
88 auto domain = std::make_shared<Mantid::API::JointDomain>();
89 domain->addDomain(std::make_shared<Mantid::API::FunctionDomain1DVector>(0, 1, 9));
90 domain->addDomain(std::make_shared<Mantid::API::FunctionDomain1DVector>(1, 2, 10));
91 domain->addDomain(std::make_shared<Mantid::API::FunctionDomain1DVector>(2, 3, 11));
96const double A0 = 0.5,
A1 = -4,
A2 = 4;
97const double B0 = 5,
B1 = -20,
B2 = 16;
104 auto &
x = ws1->mutableX(0);
105 auto &
y = ws1->mutableY(0);
106 const size_t numBins =
y.size();
107 for (
size_t i = 0; i < numBins; ++i) {
108 x[i] = -1.0 +
dX * double(i);
109 const double t =
x[i];
110 const double t2 = t * t;
111 y[i] =
A0 +
B0 * t + (
A1 +
B1 * t) * t2 + (
A2 +
B2 * t) * t2 * t2;
121 auto &
x = ws2->mutableX(0);
122 auto &
y = ws2->mutableY(0);
123 const size_t numBins =
y.size();
124 for (
size_t i = 0; i < numBins; ++i) {
125 x[i] = -1.0 +
dX * double(i);
126 const double t =
x[i];
127 y[i] =
A0 +
B0 * t + (
A1 +
B1 * t) * t * t;
136 auto &
x = ws3->mutableX(0);
137 auto &
y = ws3->mutableY(0);
138 const size_t numBins =
y.size();
139 for (
size_t i = 0; i < numBins; ++i) {
140 x[i] = -1.0 +
dX * double(i);
141 const double t =
x[i];
142 y[i] =
A0 +
B0 * t + (
A2 +
B2 * t) * t * t * t * t;
This is a specialization of IFunction for functions of one real argument.
Attribute is a non-fitting parameter.
int asInt() const
Returns int value if attribute is a int, throws exception otherwise.
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
void declareAttribute(const std::string &name, const API::IFunction::Attribute &defaultValue)
Declare a single attribute.
Represents the Jacobian in IFitFunction::functionDeriv.
virtual void set(size_t iY, size_t iP, double value)=0
Set a value to a Jacobian matrix element.
Implements the part of IFunction interface dealing with parameters.
void declareParameter(const std::string &name, double initValue=0, const std::string &description="") override
Declare a new parameter.
double getParameter(size_t i) const override
Get i-th parameter.
void functionDeriv1D(Mantid::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.
MultiDomainFunctionTest_Function()
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< Mantid::API::JointDomain > makeMultiDomainDomain3()
std::shared_ptr< Mantid::API::MultiDomainFunction > makeMultiDomainFunction3()
Mantid::API::MatrixWorkspace_sptr makeMultiDomainWorkspace2()
Mantid::API::MatrixWorkspace_sptr makeMultiDomainWorkspace3()
Mantid::API::MatrixWorkspace_sptr makeMultiDomainWorkspace1()
Helper class which provides the Collimation Length for SANS instruments.