GeographicLib 2.7

Loading...
Searching...
No Matches
GeographicLib::TrigfunExt Class Reference

A function defined by its derivative and its inverse. More...

`#include <GeographicLib/Trigfun.hpp>`

## Public Member Functions
| TrigfunExt ()
| TrigfunExt (const std::function< real(real)> &fp, real halfp, bool sym=false, real scale=-1)
real | operator() (real x) const
real | deriv (real x) const
real | inv (real z) const
void | ComputeInverse ()
bool | Symmetric () const
int | NCoeffs () const
int | NCoeffsInv () const
real | Max () const
real | HalfPeriod () const
real | HalfRange () const
real | Slope () const

## Detailed Description

A function defined by its derivative and its inverse.

This is an extension of Trigfun which allows a function to be defined by its derivative. In this case the derivative must be even, so that its integral is odd (and taken to be zero at the origin).

In addition, this class offers a flexible interface to computing the inverse of the function. If the inverse is only required at a few points

Example of use:

// Example of using the GeographicLib::TrigfunExt class.
#include <iostream>
#include <iomanip>
#include <exception>
#include <GeographicLib/Trigfun.hpp>
#include <GeographicLib/EllipticFunction.hpp>
using namespace std;
using namespace GeographicLib;
int main(int argc, const char* const argv[]) {
try {
// Integrate 1/sqrt(1 - k2*sin(x)^2) and compare this to the elliptic
// integral of the first kine.
double k2 = Math::sq(0.8);
auto f = [k2] (double x) -> double
{ return 1/sqrt(1 - k2 * Math::sq(sin(x))); };
TrigfunExt tfe(f, Math::pi()/2);
cout << "Number of coefficients: " << tfe.NCoeffs() << "\n";
EllipticFunction ell(k2);
cout << "x tf(x) tf(x)-F(x)\n";
for (int i = 0; i <= 20; ++i) {
double x = i/10.0;
cout << x << " " << tfe(x) << " " << tfe(x) - ell.F(x) << "\n";
}
}
catch (const std::exception& e) {
std::cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
}
main
int main(int argc, const char *const argv[])
Definition Cart3Convert.cpp:52
EllipticFunction.hpp
Header for GeographicLib::EllipticFunction class.
Trigfun.hpp
Header for GeographicLib::Trigfun class.
GeographicLib::EllipticFunction
Elliptic integrals and functions.
Definition EllipticFunction.hpp:63
GeographicLib::Math::sq
static T sq(T x)
Definition Math.hpp:209
GeographicLib::Math::pi
static T pi()
Definition Math.hpp:187
GeographicLib::TrigfunExt
A function defined by its derivative and its inverse.
Definition Trigfun.hpp:498
GeographicLib
Namespace for GeographicLib.
Definition Accumulator.cpp:12
std
Definition NearestNeighbor.hpp:806

Definition at line 498 of file Trigfun.hpp.

## Constructor & Destructor Documentation

## ◆ TrigfunExt() [1/2]

GeographicLib::TrigfunExt::TrigfunExt | ( |  | ) |
| inline

Definition at line 532 of file Trigfun.hpp.

## ◆ TrigfunExt() [2/2]

GeographicLib::TrigfunExt::TrigfunExt | ( | const std::function< real(real)> & | fp,
|  | real | halfp,
|  | bool | sym = false,
|  | real | scale = -1 )

Constructor specifying the derivative, an even periodic function

Parameters

  [in] | fp | the derivative function, fp(x) = f'(x).
  [in] | halfp | the half period.
  [in] | sym | is fp symmetric about the quarter period point (so it contains only odd Fourier harmonics)?
  [in] | scale; | this is passed to the Trigfun constructor when finding the Fourier series for fp.

Warning
  fp must be an even periodic function. In addition fp must be nonnegative for the inverse of f to be computed (in this case, f is a monotonically increasing function). The inverse is undefined for sym = true.

## Member Function Documentation

## ◆ operator()()

real GeographicLib::TrigfunExt::operator() | ( | real | x | ) | const
| inline

Evaluate the TrigfunExt.

Parameters

  [in] | x | the function argument.

Returns
  the function value f(x).

Definition at line 556 of file Trigfun.hpp.

## ◆ deriv()

real GeographicLib::TrigfunExt::deriv | ( | real | x | ) | const
| inline

Evaluate the derivative for TrigfunExt.

Parameters

  [in] | x | the function argument.

Returns
  the value of the derivative fp(x). This uses the function object passed to the constructor.

Definition at line 564 of file Trigfun.hpp.

## ◆ inv()

real GeographicLib::TrigfunExt::inv | ( | real | z | ) | const
| inline

Evaluate the inverse of f

Parameters

  [in] | z | the value of f(x)

Returns
  the value of x = f −1(z).

This compute the inverse using Newton's method with the derivative function fp supplied on construction. Initially, the starting guess is based on just the secular component of f(x). However, if ComputeInverse() is called, a rough Trigfun approximation to the inverse is found and this is used as the starting point for Newton's method.

Definition at line 577 of file Trigfun.hpp.

## ◆ ComputeInverse()

void GeographicLib::TrigfunExt::ComputeInverse | ( |  | ) |
| inline

Compute a coarse Fourier series approximation of the inverse.

This is used to provide a better starting guess for Newton's method in inv(). Because ComputeInverse() is fairly expensive, this only makes sense if inv() will be called many times. In order to limit the expense in computing this approximate inverse, the number of Fourier components in the Trigfun for the inverse is limited to 3/2 of the number of components for f and the tolerance is set to the square root of the machine epsilon.

Definition at line 591 of file Trigfun.hpp.

## ◆ Symmetric()

bool GeographicLib::TrigfunExt::Symmetric | ( |  | ) | const
| inline

Returns
  whether the function is symmetric about the quarter period point. If it is it, then the Fourier series has only odd harmonics.

Definition at line 602 of file Trigfun.hpp.

## ◆ NCoeffs()

int GeographicLib::TrigfunExt::NCoeffs | ( |  | ) | const
| inline

Returns
  the number of terms in the Fourier series for f.

Definition at line 606 of file Trigfun.hpp.

## ◆ NCoeffsInv()

int GeographicLib::TrigfunExt::NCoeffsInv | ( |  | ) | const
| inline

Returns
  the number of terms in the Fourier series for f−1.

Definition at line 611 of file Trigfun.hpp.

## ◆ Max()

real GeographicLib::TrigfunExt::Max | ( |  | ) | const
| inline

Returns
  Max() for the underlying Trigfun.

Definition at line 617 of file Trigfun.hpp.

## ◆ HalfPeriod()

real GeographicLib::TrigfunExt::HalfPeriod | ( |  | ) | const
| inline

Returns
  HalfPeriod() for the underlying Trigfun.

Definition at line 621 of file Trigfun.hpp.

## ◆ HalfRange()

real GeographicLib::TrigfunExt::HalfRange | ( |  | ) | const
| inline

Returns
  HalfRange() for the underlying Trigfun.

Definition at line 625 of file Trigfun.hpp.

## ◆ Slope()

real GeographicLib::TrigfunExt::Slope | ( |  | ) | const
| inline

Returns
  Slope() for the underlying Trigfun.

Definition at line 629 of file Trigfun.hpp.

The documentation for this class was generated from the following file:

- Trigfun.hpp