1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-06-18 23:37:05 +01:00

numerical derivative class with arbitrary improvement order and step auto-tuning

This commit is contained in:
2014-09-26 18:40:52 +01:00
parent 8ccc529776
commit 0fdd76b19d
6 changed files with 325 additions and 0 deletions

View File

@ -16,6 +16,7 @@ endif
noinst_PROGRAMS = \
exCompiledDoubleFunction\
exDerivative \
exFit \
exIntegrator \
exMat \
@ -29,6 +30,10 @@ exCompiledDoubleFunction_SOURCES = exCompiledDoubleFunction.cpp
exCompiledDoubleFunction_CFLAGS = -g -O2
exCompiledDoubleFunction_LDFLAGS = -L../lib/.libs -lLatAnalyze
exDerivative_SOURCES = exDerivative.cpp
exDerivative_CFLAGS = -g -O2
exDerivative_LDFLAGS = -L../lib/.libs -lLatAnalyze
exFit_SOURCES = exFit.cpp
exFit_CFLAGS = -g -O2
exFit_LDFLAGS = -L../lib/.libs -lLatAnalyze

40
examples/exDerivative.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <iostream>
#include <LatAnalyze/Derivative.hpp>
#include <LatAnalyze/CompiledFunction.hpp>
#include <LatAnalyze/Math.hpp>
using namespace std;
using namespace Latan;
int main(int argc, char *argv[])
{
string source;
Index maxOrder;
double x;
if (argc != 4)
{
cerr << "usage: " << argv[0] << " <function> <max order> <point>";
cerr << endl;
return EXIT_FAILURE;
}
source = argv[1];
maxOrder = strTo<Index>(argv[2]);
x = strTo<double>(argv[3]);
CompiledDoubleFunction f(1, source);
CentralDerivative df(f);
for (Index i = 1; i <= 4; ++i)
{
cout << "--- O(h^" << 2*i << ") derivative" << endl;
for (Index j = 0; j <= maxOrder; ++j)
{
df.setOrder(j, i);
cout << "d^" << j << "f(" << x << ")= " << df(x) << endl;
}
}
return 0;
}