mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-06-20 08:16:55 +01:00
overhaul of the function class
This commit is contained in:
@ -17,14 +17,14 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
source = argv[1];
|
||||
|
||||
CompiledDoubleFunction f(1, source);
|
||||
CompiledDoubleFunction f(source, 1);
|
||||
|
||||
cout << "-- Program:" << endl << f << endl;
|
||||
cout << "-- Values:" << endl;
|
||||
for (double x = 0.0; x < 10.0; x += 0.5)
|
||||
{
|
||||
cout << "f(" << right << setw(6) << strFrom<double>(x) << ")= "
|
||||
<< f(x) << endl;
|
||||
<< f(&x) << endl;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -23,7 +23,7 @@ int main(int argc, char *argv[])
|
||||
maxOrder = strTo<Index>(argv[2]);
|
||||
x = strTo<double>(argv[3]);
|
||||
|
||||
CompiledDoubleFunction f(1, source);
|
||||
DoubleFunction f = compile(source, 1);
|
||||
CentralDerivative df(f);
|
||||
|
||||
for (Index i = 1; i <= 4; ++i)
|
||||
@ -32,7 +32,7 @@ int main(int argc, char *argv[])
|
||||
for (Index j = 0; j <= maxOrder; ++j)
|
||||
{
|
||||
df.setOrder(j, i);
|
||||
cout << "d^" << j << "f(" << x << ")= " << df(x) << endl;
|
||||
cout << "d^" << j << "f(" << x << ")= " << df(&x) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,10 @@ const double exactPar[2] = {0.5,5.0}, dx = 10.0/static_cast<double>(nPoint);
|
||||
int main(void)
|
||||
{
|
||||
// generate fake data
|
||||
XYStatData data(nPoint, 1, 1);
|
||||
RandGen rg;
|
||||
double x_k, y_k;
|
||||
CompiledDoubleModel f(1, 2, "return p_1*exp(-x_0*p_0);");
|
||||
XYStatData data(nPoint, 1, 1);
|
||||
RandGen rg;
|
||||
double x_k, y_k;
|
||||
DoubleModel f = compile("return p_1*exp(-x_0*p_0);", 1, 2);
|
||||
|
||||
for (Index k = 0; k < nPoint; ++k)
|
||||
{
|
||||
|
@ -20,9 +20,9 @@ int main(int argc, char* argv[])
|
||||
xMin = strTo<double>(argv[2]);
|
||||
xMax = strTo<double>(argv[3]);
|
||||
|
||||
CompiledDoubleFunction f(1, source);
|
||||
GslQagsIntegrator integrator;
|
||||
double result;
|
||||
DoubleFunction f = compile(source, 1);
|
||||
GslQagsIntegrator integrator;
|
||||
double result;
|
||||
|
||||
result = integrator(f, xMin, xMax);
|
||||
cout << "function integral on [" << xMin << ", " << xMax << "] = ";
|
||||
|
@ -17,12 +17,15 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
source = argv[1];
|
||||
|
||||
CompiledDoubleFunction f(1, source);
|
||||
MinuitMinimizer minimizer(1);
|
||||
DoubleFunction f = compile(source, 1);
|
||||
MinuitMinimizer minimize(1);
|
||||
DVec init(1);
|
||||
double min;
|
||||
|
||||
minimizer.setVerbosity(Minimizer::Verbosity::Debug);
|
||||
min = minimizer(f)(0);
|
||||
|
||||
init(0) = 0.1;
|
||||
minimize.setInit(init);
|
||||
minimize.setVerbosity(Minimizer::Verbosity::Debug);
|
||||
min = minimize(f)(0);
|
||||
cout << "function minimum = " << min << endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -20,11 +20,10 @@ int main(void)
|
||||
}
|
||||
p << PlotRange(Axis::x, -5.0, 5.0) << PlotRange(Axis::y, -5.0, 20.0);
|
||||
p << Color("rgb 'blue'") << PlotFunction(StdMath::tgamma, -5, 5);
|
||||
p << PlotFunction(CompiledDoubleFunction(1, "return cos(x_0)^2;"), -5, 5);
|
||||
p << PlotFunction(compile("return cos(x_0)^2;", 1), -5, 5);
|
||||
p << Color("rgb 'brown'") << PlotCommand("x**3");
|
||||
p << PlotCommand("x**2");
|
||||
p << PlotFunction(TabFunction(x, y), 0.,
|
||||
static_cast<double>(nPoint)/2.0 - 1.1);
|
||||
p << PlotFunction(interpolate(x, y), 0., nPoint/2.0 - 1.1);
|
||||
cout << p << endl;
|
||||
p.display();
|
||||
|
||||
|
@ -8,8 +8,8 @@ using namespace Latan;
|
||||
int main(void)
|
||||
{
|
||||
constexpr double a = 1., b = 10.;
|
||||
DoubleFunction f1(2, [a](const double *x){return a*(1.-x[0]);});
|
||||
DoubleFunction f2(2, [b](const double *x){return b*(x[1]-x[0]*x[0]);});
|
||||
DoubleFunction f1([a](const double *x){return a*(1.-x[0]);}, 2);
|
||||
DoubleFunction f2([b](const double *x){return b*(x[1]-x[0]*x[0]);}, 2);
|
||||
vector<DoubleFunction *> system = {&f1, &f2};
|
||||
GslHybridRootFinder solve(2);
|
||||
DVec init(2), x;
|
||||
|
Reference in New Issue
Block a user