Theoretica
A C++ numerical and automatic mathematical library
Loading...
Searching...
No Matches
taylor.h
Go to the documentation of this file.
1
5
6#ifndef THEORETICA_TAYLOR_H
7#define THEORETICA_TAYLOR_H
8
9#include "../polynomial/polynomial.h"
10#include "../autodiff/dual.h"
11#include "../autodiff/dual2.h"
12
13
14namespace theoretica {
15
17 namespace taylor {
18
19
29 template<typename DualFunction>
31
32 dual d = f(dual(x0, 1));
33 real fx = d.Re();
34 real dfx = d.Dual();
35
37 P += polynomial<>({-x0, 1}) * dfx;
38
39 return P;
40 }
41
42
52 template<typename Dual2Function>
54
55 dual2 d = f(dual2(x0, 1, 0));
56 real fx = d.Re();
57 real dfx = d.Dual1();
58 real d2fx = d.Dual2();
59
61 P += polynomial<>({-x0, 1}) * dfx;
62 P += polynomial<>({square(x0), -2 * x0, 1}) * (d2fx / 2.0);
63
64 return P;
65 }
66
67 }
68
69}
70
71
72#endif
Second order dual number class.
Definition dual2.h:29
real Dual2() const
Return second order dual part.
Definition dual2.h:95
real Re() const
Return real part.
Definition dual2.h:85
real Dual1() const
Return first order dual part.
Definition dual2.h:90
Dual number class.
Definition dual.h:28
const real & Dual() const
Return dual part.
Definition dual.h:96
const real & Re() const
Return real part.
Definition dual.h:75
polynomial< real > expand_quadratic(Dual2Function f, real x0=0)
Computes the second order Taylor expansion of a generic function around x0, computed using dual numbe...
Definition taylor.h:53
polynomial< real > expand_linear(DualFunction f, real x0=0)
Computes the first order Taylor expansion of a generic function around x0, computed using dual number...
Definition taylor.h:30
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
std::remove_reference_t< decltype(std::declval< Structure >()[0])> vector_element_t
Extract the type of a vector (or any indexable container) from its operator[].
Definition core_traits.h:134
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition dual2_functions.h:23