...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
#include <boost/math/special_functions/jacobi_elliptic.hpp>
namespace boost { namespace math { template <class T, class U, class V> calculated-result-type jacobi_elliptic(T k, U u, V* pcn, V* pdn); template <class T, class U, class V, class Policy> calculated-result-type jacobi_elliptic(T k, U u, V* pcn, V* pdn, const Policy&); }} // namespaces
The function jacobi_elliptic calculates the three copolar Jacobi elliptic functions sn(u, k), cn(u, k) and dn(u, k). The returned value is sn(u, k), and if provided, *pcn is set to cn(u, k), and *pdn is set to dn(u, k).
The functions are defined as follows, given:
The the angle φ is called the amplitude and:
Note | |
---|---|
φ is called the amplitude. k is called the modulus. |
Caution | |
---|---|
Rather like other elliptic functions, the Jacobi functions are expressed in a variety of different ways. In particular, the parameter k (the modulus) may also be expressed using a modular angle α, or a parameter m. These are related by: k = sinα m = k2 = sin2α So that the function sn (for example) may be expressed as either: sn(u, k) sn(u \ α) sn(u| m) To further complicate matters, some texts refer to the complement of the parameter m, or 1 - m, where: 1 - m = 1 - k2 = cos2α This implementation uses k throughout, and makes this the first argument to the functions: this is for alignment with the elliptic integrals which match the requirements of the Technical Report on C++ Library Extensions. However, you should be extra careful when using these functions! |
The final Policy argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the policy documentation for more details.
The following graphs illustrate how these functions change as k changes: for small k these are sine waves, while as k tends to 1 they become hyperbolic functions:
These functions are computed using only basic arithmetic operations and trigomometric functions, so there isn't much variation in accuracy over differing platforms. Typically errors are trivially small for small angles, and as is typical for cyclic functions, grow as the angle increases. Note that only results for the widest floating point type on the system are given as narrower types have effectively zero error. All values are relative errors in units of epsilon.
Table 6.70. Error rates for jacobi_cn
GNU C++ version 7.1.0 |
GNU C++ version 7.1.0 |
Sun compiler version 0x5150 |
Microsoft Visual C++ version 14.1 |
|
---|---|---|---|---|
Jacobi Elliptic: Mathworld Data |
Max = 0ε (Mean = 0ε) |
Max = 71.6ε (Mean = 19.3ε) |
Max = 71.6ε (Mean = 19.4ε) |
Max = 45.8ε (Mean = 11.4ε) |
Jacobi Elliptic: Random Data |
Max = 0.816ε (Mean = 0.0563ε) |
Max = 1.68ε (Mean = 0.443ε) |
Max = 1.68ε (Mean = 0.454ε) |
Max = 1.83ε (Mean = 0.455ε) |
Jacobi Elliptic: Random Small Values |
Max = 0ε (Mean = 0ε) |
Max = 10.4ε (Mean = 0.594ε) |
Max = 10.4ε (Mean = 0.602ε) |
Max = 26.2ε (Mean = 1.17ε) |
Jacobi Elliptic: Modulus near 1 |
Max = 0.919ε (Mean = 0.127ε) |
Max = 675ε (Mean = 87.1ε) |
Max = 675ε (Mean = 86.8ε) |
Max = 513ε (Mean = 126ε) |
Jacobi Elliptic: Large Phi |
Max = 14.2ε (Mean = 0.927ε) |
Max = 2.97e+04ε (Mean = 1.9e+03ε) |
Max = 2.97e+04ε (Mean = 1.9e+03ε) |
Max = 3.27e+04ε (Mean = 1.93e+03ε) |
Table 6.71. Error rates for jacobi_dn
GNU C++ version 7.1.0 |
GNU C++ version 7.1.0 |
Sun compiler version 0x5150 |
Microsoft Visual C++ version 14.1 |
|
---|---|---|---|---|
Jacobi Elliptic: Mathworld Data |
Max = 0ε (Mean = 0ε) |
Max = 49ε (Mean = 14ε) |
Max = 49ε (Mean = 14ε) |
Max = 34.3ε (Mean = 8.71ε) |
Jacobi Elliptic: Random Data |
Max = 0ε (Mean = 0ε) |
Max = 1.53ε (Mean = 0.473ε) |
Max = 1.53ε (Mean = 0.481ε) |
Max = 1.52ε (Mean = 0.466ε) |
Jacobi Elliptic: Random Small Values |
Max = 0.5ε (Mean = 0.0122ε) |
Max = 22.4ε (Mean = 0.777ε) |
Max = 22.4ε (Mean = 0.763ε) |
Max = 16.1ε (Mean = 0.685ε) |
Jacobi Elliptic: Modulus near 1 |
Max = 2.28ε (Mean = 0.194ε) |
Max = 3.75e+03ε (Mean = 293ε) |
Max = 3.75e+03ε (Mean = 293ε) |
Max = 6.24e+03ε (Mean = 482ε) |
Jacobi Elliptic: Large Phi |
Max = 14.1ε (Mean = 0.897ε) |
Max = 2.82e+04ε (Mean = 1.79e+03ε) |
Max = 2.82e+04ε (Mean = 1.79e+03ε) |
Max = 1.67e+04ε (Mean = 1e+03ε) |
Table 6.72. Error rates for jacobi_sn
GNU C++ version 7.1.0 |
GNU C++ version 7.1.0 |
Sun compiler version 0x5150 |
Microsoft Visual C++ version 14.1 |
|
---|---|---|---|---|
Jacobi Elliptic: Mathworld Data |
Max = 0ε (Mean = 0ε) |
Max = 341ε (Mean = 80.7ε) |
Max = 341ε (Mean = 80.7ε) |
Max = 481ε (Mean = 113ε) |
Jacobi Elliptic: Random Data |
Max = 0ε (Mean = 0ε) |
Max = 2.01ε (Mean = 0.584ε) |
Max = 2.01ε (Mean = 0.593ε) |
Max = 1.92ε (Mean = 0.567ε) |
Jacobi Elliptic: Random Small Values |
Max = 0ε (Mean = 0ε) |
Max = 1.99ε (Mean = 0.347ε) |
Max = 1.99ε (Mean = 0.347ε) |
Max = 2.11ε (Mean = 0.385ε) |
Jacobi Elliptic: Modulus near 1 |
Max = 0ε (Mean = 0ε) |
Max = 109ε (Mean = 7.35ε) |
Max = 109ε (Mean = 7.38ε) |
Max = 23.2ε (Mean = 1.85ε) |
Jacobi Elliptic: Large Phi |
Max = 12ε (Mean = 0.771ε) |
Max = 2.45e+04ε (Mean = 1.51e+03ε) |
Max = 2.45e+04ε (Mean = 1.51e+03ε) |
Max = 4.36e+04ε (Mean = 2.54e+03ε) |
The tests use a mixture of spot test values calculated using the online calculator at functions.wolfram.com, and random test data generated using MPFR at 1000-bit precision and this implementation.
For k > 1 we apply the relations:
Then filter off the special cases:
sn(0, k) = 0 and cn(0, k) = dn(0, k) = 1.
sn(u, 0) = sin(u), cn(u, 0) = cos(u) and dn(u, 0) = 1.
sn(u, 1) = tanh(u), cn(u, 1) = dn(u, 1) = 1 / cosh(u).
And for k4 < ε we have:
Otherwise the values are calculated using the method of arithmetic geometric means.