|
GeographicLib 2.6
|
Representing a function by a Fourier series. More...
#include <GeographicLib/Trigfun.hpp>
Public Member Functions | |
| Trigfun () | |
| Trigfun (int n, const std::function< real(real)> &f, bool odd, bool sym, real halfp, bool centerp=false) | |
| Trigfun (const std::function< real(real)> &f, bool odd, bool sym, real halfp, int nmax=1<< 16, real tol=0, real scale=-1) | |
| Trigfun (const std::function< real(real, real)> &f, bool odd, bool sym, real halfp, int nmax=1<< 16, real tol=0, real scale=-1) | |
| void | setsecular (real f0) |
| real | operator() (real x) const |
| Trigfun | integral () const |
| Trigfun | inverse (const std::function< real(real)> &fp, int nmax=1<< 16, real tol=0, real scale=-1) const |
| bool | Odd () const |
| bool | Symmetric () const |
| real | HalfPeriod () const |
| int | NCoeffs () const |
| real | Max () const |
| real | HalfRange () const |
| real | Slope () const |
Representing a function by a Fourier series.
This class mimic the functionality of Chebfun's 'trig' representation of periodic functions. Key differences are:
Assuming the half period = h, the function f(x) is represented as follows, here \( = (\pi/h) x\):
Here we compute FFTs using the kissfft package https://github.com/mborgerding/kissfft by Mark Borgerding.
Example of use:
Definition at line 65 of file Trigfun.hpp.
|
inline |
Default constructor specifying with the function f(x) = 0.
Definition at line 271 of file Trigfun.hpp.
| GeographicLib::Trigfun::Trigfun | ( | int | n, |
| const std::function< real(real)> & | f, | ||
| bool | odd, | ||
| bool | sym, | ||
| real | halfp, | ||
| bool | centerp = false ) |
Construct a Trigfun with a given number of samples a function.
| [in] | n | the number of samples. |
| [in] | f | the function. |
| [in] | odd | is the function odd? If it's not odd, then it is even. |
| [in] | sym | is the function symmetric about the quarter period point (so it contains only odd Fourier harmonics)? |
| [in] | halfp | the half period. |
| [in] | centerp | whether to sample on a centered grid (default false). |
For sym = false, n is the number of samples in a half period, and spacing between the samples is halfp/n. (If centerp = false and oddp = false, the function is, in fact sampled n + 1 times.) The number of points given to the FFT routine is 2n.
For sym = true, n is the number of samples in a quarter period, and spacing between the samples is halfp/(2n). The number of points given to the FFT routine is 4n.
| GeographicLib::Trigfun::Trigfun | ( | const std::function< real(real)> & | f, |
| bool | odd, | ||
| bool | sym, | ||
| real | halfp, | ||
| int | nmax = 1<< 16, | ||
| real | tol = 0, | ||
| real | scale = -1 ) |
Construct a Trigfun from a function of one argument.
| [in] | f | the function. |
| [in] | odd | is the function odd? If it's not odd, then it is even. |
| [in] | sym | is the function symmetric about the quarter period point (so it contains only odd Fourier harmonics)? |
| [in] | halfp | the half period. |
| [in] | nmax | the maximum number of points in a half/quarter period (default 2^16 = 65536). |
| [in] | tol | the tolerance, the default value 0 means use the machine epsilon. |
| [in] | scale; | if scale is negative (the default), tol sets the error relative to the largest Fourier coeffient. Otherwise, the error is relative to the maximum of the largest Fourier coefficient and scale. |
The constructor successively doubles the number of sample points and updating the Fourier coefficients accordingly until the high order coefficients become sufficiently small. At that point Fourier series is truncated discarding some of the trailing coefficients. This mimics the method used by Chebfun. In particular, the method used to truncate the series is taken from Aurentz and L. N. Trefethen, Chopping a Chebyshev series (2017); preprint.
| GeographicLib::Trigfun::Trigfun | ( | const std::function< real(real, real)> & | f, |
| bool | odd, | ||
| bool | sym, | ||
| real | halfp, | ||
| int | nmax = 1<< 16, | ||
| real | tol = 0, | ||
| real | scale = -1 ) |
Construct a Trigfun from a function of two arguments.
| [in] | f | the function. |
| [in] | odd | is the function odd? If it's not odd, then it is even. |
| [in] | sym | is the function symmetric about the quarter period point (so it contains only odd Fourier harmonics)? |
| [in] | halfp | the half period. |
| [in] | nmax | the maximum number of points in a half/quarter period (default 2^16 = 65536). |
| [in] | tol | the tolerance, the default value 0 means use the machine epsilon. |
| [in] | scale; | if scale is negative (the default), tol sets the error relative to the largest Fourier coeffient. Otherwise, the error is relative to the maximum of the largest Fourier coefficient and scale. |
This accommodates the situation where the inverse of a Trigfun g is being computed using inverse(). In this case f(x, y0) returns the value y such that g(y) = x. This is typically found using Newton's method which requires a starting guess y0. In the implementation of inverse(), the Fourier representation is successively refined by doubling the number samples. At each stage, a good estimate of the function values at the new points is found by using the current Fourier representation.
| void GeographicLib::Trigfun::setsecular | ( | real | f0 | ) |
Set the coefficient of the secular term
| [in] | f0 | the value of f(halfp). |
| real GeographicLib::Trigfun::operator() | ( | real | x | ) | const |
| Trigfun GeographicLib::Trigfun::integral | ( | ) | const |
The integral of a Trigfun.
|
inline |
Produce a Trigfun for the inverse of f.
| [in] | fp | the derivative of f(x). |
| [in] | nmax | the maximum number of points in a quarter period (default 2^16 = 65536). |
| [in] | tol | the tolerance using in terminating the root finding. tol = 0 (the defaulat) mean to use the machine epsilon. |
| [in] | scale; | if scale is negative (the default), tol sets the error relative to the largest Fourier coeffient. Otherwise, the error is relative to the maximum of the largest Fourier coefficient and scale. |
As with the normal constructor this routine successively doubles the number of sample points, which are computed using Newton's method. A good starting guess for Newton's method is provided by the previous Fourier approximation. As a result the average number of Newton iterations per sample point is about 1 or 2.
scale is used when f(x) is a correction term added to a larger contribution; and it would then be the magnitude of the larger contribution.
Definition at line 433 of file Trigfun.hpp.
|
inline |
Definition at line 442 of file Trigfun.hpp.
|
inline |
Definition at line 447 of file Trigfun.hpp.
|
inline |
Definition at line 451 of file Trigfun.hpp.
Referenced by Slope().
|
inline |
Definition at line 455 of file Trigfun.hpp.
| real GeographicLib::Trigfun::Max | ( | ) | const |
Referenced by HalfRange().
|
inline |
For a Trigfun containing a secular contribution this is the value of the function tat the half perioid. Otherwise Max() is returned.
Definition at line 471 of file Trigfun.hpp.
References Max(), and GeographicLib::Math::pi().
Referenced by Slope().
|
inline |
For a Trigfun containing a secular contribution this is the slope of the secular component. Otherwise 0 is returned..
Definition at line 480 of file Trigfun.hpp.
References HalfPeriod(), and HalfRange().