6 #ifndef DERIVATION_THEORETICA_H
7 #define DERIVATION_THEORETICA_H
9 #include "../core/function.h"
10 #include "../polynomial/polynomial.h"
20 template<
typename Field = real>
23 if (p.coeff.size() == 0) {
28 if (p.coeff.size() == 1)
32 Dp.coeff.resize(p.coeff.size() - 1);
34 for (
unsigned int i = 1; i < p.
size(); ++i)
35 Dp.coeff[i - 1] = p[i] * i;
52 for (
unsigned int i = 0; i + 1 < p.
size(); ++i) {
54 const unsigned int pos = p.
size() - i - 1;
55 dp = pos * p[pos] + x * dp;
70 typename RealFunction = std::function<
real(
real)>,
71 enable_real_func<RealFunction> =
true
74 return (f(x + h) - f(x - h)) / (2.0 * h);
86 typename RealFunction = std::function<
real(
real)>,
87 enable_real_func<RealFunction> =
true
90 return (f(x + h) - f(x)) / h;
102 typename RealFunction = std::function<
real(
real)>,
103 enable_real_func<RealFunction> =
true
106 return (f(x) - f(x - h)) / h;
118 typename RealFunction = std::function<
real(
real)>,
119 enable_real_func<RealFunction> =
true
135 typename RealFunction = std::function<
real(
real)>,
136 enable_real_func<RealFunction> =
true
140 real A[degree][degree];
142 for (
unsigned int i = 0; i < degree; ++i) {
144 for (
unsigned int n = 0; n <= i; ++n) {
146 unsigned int m = i - n;
152 A[n][m] = (coeff * A[n - 1][m + 1] - A[n - 1][m]) / (coeff - 1);
158 return A[degree - 1][0];
170 typename RealFunction = std::function<
real(
real)>,
171 enable_real_func<RealFunction> =
true
186 typename RealFunction = std::function<
real(
real)>,
187 enable_real_func<RealFunction> =
true
190 return (f(x + h) - (2 * f(x)) + f(x - h)) / (h * h);
A polynomial of arbitrary order.
Definition: polynomial.h:25
size_t size() const
Get the number of coefficients.
Definition: polynomial.h:119
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compiling opti...
Definition: error.h:219
Main namespace of the library which contains all functions and objects.
Definition: algebra.h:27
double real
A real number, defined as a floating point type.
Definition: constants.h:198
real deriv_forward(RealFunction f, real x, real h=CALCULUS_DERIV_STEP)
Approximate the first derivative of a real function using the forward method.
Definition: deriv.h:89
constexpr real CALCULUS_DERIV_STEP
Default variation for derivative approximation.
Definition: constants.h:318
real deriv_ridders(RealFunction f, real x, real h=0.01, unsigned int degree=3)
Approximate the first derivative of a real function using Ridder's method of arbitrary degree.
Definition: deriv.h:138
real deriv_ridders2(RealFunction f, real x, real h=CALCULUS_DERIV_STEP)
Approximate the first derivative of a real function using Ridder's method of second degree.
Definition: deriv.h:121
real deriv_central(RealFunction f, real x, real h=CALCULUS_DERIV_STEP)
Approximate the first derivative of a real function using the central method.
Definition: deriv.h:73
real deriv2(RealFunction f, real x, real h=CALCULUS_DERIV_STEP)
Approximate the second derivative of a real function using the best available algorithm.
Definition: deriv.h:189
real deriv_backward(RealFunction f, real x, real h=CALCULUS_DERIV_STEP)
Approximate the first derivative of a real function using the backward method.
Definition: deriv.h:105
polynomial< Field > deriv(const polynomial< Field > &p)
Compute the exact derivative of a polynomial function.
Definition: deriv.h:21
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition: dual2_functions.h:23
real nan()
Return a quiet NaN number in floating point representation.
Definition: error.h:54