File: jacobi_elliptic.qbk

package info (click to toggle)
scipy 1.16.0-1exp7
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 234,820 kB
  • sloc: cpp: 503,145; python: 344,611; ansic: 195,638; javascript: 89,566; fortran: 56,210; cs: 3,081; f90: 1,150; sh: 848; makefile: 785; pascal: 284; csh: 135; lisp: 134; xml: 56; perl: 51
file content (558 lines) | stat: -rw-r--r-- 14,045 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
[/
Copyright (c) 2012 John Maddock
Use, modification and distribution are subject to the
Boost Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
]

[section:jacobi Jacobi Elliptic Functions]

[section:jac_over Overview of the Jacobi Elliptic Functions]

There are twelve Jacobi Elliptic functions, of which the three copolar functions ['sn], ['cn] and ['dn] are the most important
as the other nine can be computed from these three
[footnote [@http://en.wikipedia.org/wiki/Jacobi_elliptic_functions Wikipedia: Jacobi elliptic functions]]
[footnote [@http://mathworld.wolfram.com/JacobiEllipticFunctions.html Weisstein, Eric W. "Jacobi Elliptic Functions." From MathWorld - A Wolfram Web Resource.]]
[footnote [@http://dlmf.nist.gov/22 Digital Library of Mathematical Functions: Jacobian Elliptic Functions, Reinhardt, W. P.,  Walker, O. L.]].

These functions each take two arguments: a parameter, and a variable as described below.

Like all elliptic functions these can be parameterised in a number of ways:

* In terms of a parameter ['m].
* In terms of the elliptic modulus ['k] where ['m = k[super 2]].
* In terms of the modular angle [alpha], where ['m = sin[super 2][thin][alpha]].

In our implementation, these functions all take the elliptic modulus /k/ as the parameter.

In addition the variable /u/ is sometimes expressed as an amplitude [phi], in our implementation we always use /u/.

Finally note that our functions all take the elliptic modulus /k/ as the *first* argument - this is for alignment with
the Elliptic Integrals (but is different from other implementations, for example Mathworks).

A simple example comparing use of __WolframAlpha with Boost.Math (including much higher precision using Boost.Multiprecision)
is [@../../example/jacobi_zeta_example.cpp jacobi_zeta_example.cpp].

There are twelve functions for computing the twelve individual Jacobi elliptic functions: __jacobi_cd, __jacobi_cn, __jacobi_cs,
__jacobi_dc, __jacobi_dn, __jacobi_ds, __jacobi_nc, __jacobi_nd, __jacobi_ns, __jacobi_sc, __jacobi_sd and __jacobi_sn.

They are all called as for example:

   jacobi_cs(k, u);

Note however that these individual functions are all really thin wrappers around the function __jacobi_elliptic which calculates
the three copolar functions ['sn], ['cn] and ['dn] in a single function call. 

[tip If you need more than one of these functions
for a given set of arguments, it's most efficient to use __jacobi_elliptic.]

[endsect] [/section:jac_over Overview of the Jacobi Elliptic Functions]

[section:jacobi_elliptic Jacobi Elliptic SN, CN and DN]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U, class V>
   ``__sf_result`` jacobi_elliptic(T k, U u, V* pcn, V* pdn);

   template <class T, class U, class V, class Policy>
   ``__sf_result`` jacobi_elliptic(T k, U u, V* pcn, V* pdn, const Policy&);

  }} // namespaces
  
[heading Description]

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:

[equation jacobi1]

The the angle ['[phi]] is called the ['amplitude] and:

[equation jacobi2]

[note 
  ['[phi]] is called the amplitude.
  ['k] is called the elliptic 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 [alpha], or a parameter /m/.  These are related by:

[expression k = sin [alpha]]

[expression m = k[super 2] = sin[super 2][alpha]]

So that the function ['sn] (for example) may be expressed as
either:

[expression sn(u, k)]

[expression sn(u \\ [alpha])]

[expression sn(u | m)]

To further complicate matters, some texts refer to the ['complement
of the parameter m], or 1 - m, where:

[expression 1 - m = 1 - k[super 2] = cos[super 2][alpha]]

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 [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf
Technical Report on C++ Library Extensions].  However, you should
be extra careful when using these functions!]

[optional_policy]

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:

[graph jacobi_sn]

[graph jacobi_cn]

[graph jacobi_dn]

[heading Accuracy]

These functions are computed using only basic arithmetic operations and trigonometric 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 __zero_error.  All values
are relative errors in units of epsilon.

[table_jacobi_cn]

[table_jacobi_dn]

[table_jacobi_sn]

[heading Testing]

The tests use a mixture of spot test values calculated using the online
calculator at [@http://functions.wolfram.com/ functions.wolfram.com],
and random test data generated using
MPFR at 1000-bit precision and this implementation.

[heading Implementation]

For ['k > 1] we apply the relations:

[equation jacobi3]

Then filter off the special cases:

[expression ['sn(0, k) = 0] and ['cn(0, k) = dn(0, k) = 1]]

[expression ['sn(u, 0) = sin(u), cn(u, 0) = cos(u) and dn(u, 0) = 1]]

[expression ['sn(u, 1) = tanh(u), cn(u, 1) = dn(u, 1) = 1 / cosh(u)]]

And for ['k[super 4] < [epsilon]] we have:

[equation jacobi4]

Otherwise the values are calculated using the method of [@http://dlmf.nist.gov/22.20#SS2 arithmetic geometric means].

[endsect] [/section:jacobi_elliptic Jacobi Elliptic SN, CN and DN]


[section:jacobi_cd Jacobi Elliptic Function cd]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_cd(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_cd(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['cd].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic, with:

[expression ['cd(u, k) = cn(u, k) / dn(u, k)]]

[graph jacobi_cd]

[endsect] [/section:jacobi_cd Jacobi Elliptic Function cd]


[section:jacobi_cn Jacobi Elliptic Function cn]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_cn(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_cn(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['cn].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic.

[graph jacobi_cn]

[endsect] [/section:jacobi_cn Jacobi Elliptic Function cn]


[section:jacobi_cs Jacobi Elliptic Function cs]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_cs(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_cs(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['cs].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic, with:

[expression ['cs(u, k) = cn(u, k) / sn(u, k)]]

[graph jacobi_cs]

[endsect] [/section:jacobi_cs Jacobi Elliptic Function cs]


[section:jacobi_dc Jacobi Elliptic Function dc]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_dc(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_dc(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['dc].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic, with:

[expression ['dc(u, k) = dn(u, k) / cn(u, k)]]

[graph jacobi_dc]

[endsect] [/section:jacobi_dc Jacobi Elliptic Function dc]

[section:jacobi_dn Jacobi Elliptic Function dn]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_dn(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_dn(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['dn].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic.

[graph jacobi_dn]

[endsect]

[section:jacobi_ds Jacobi Elliptic Function ds]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_ds(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_ds(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['ds].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic, with:

[expression ['ds(u, k) = dn(u, k) / sn(u, k)]]

[graph jacobi_ds]

[endsect] [/section:jacobi_dn Jacobi Elliptic Function dn]

[section:jacobi_nc Jacobi Elliptic Function nc]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_nc(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_nc(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['nc].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic, with:

[expression ['nc(u, k) = 1 / cn(u, k)]]

[graph jacobi_nc]

[endsect] [/section:jacobi_nc Jacobi Elliptic Function nc]

[section:jacobi_nd Jacobi Elliptic Function nd]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_nd(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_nd(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['nd].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic, with:

[expression ['nd(u, k) = 1 / dn(u, k)]]

[graph jacobi_nd]

[endsect] [/section:jacobi_nd Jacobi Elliptic Function nd]

[section:jacobi_ns Jacobi Elliptic Function ns]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_ns(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_ns(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['ns].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic, with:

[expression ['ns(u, k) = 1 / sn(u, k)]]

[graph jacobi_ns]

[endsect] [/section:jacobi_ns Jacobi Elliptic Function ns]

[section:jacobi_sc Jacobi Elliptic Function sc]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_sc(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_sc(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['sc].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic, with:

[expression ['sc(u, k) = sn(u, k) / cn(u, k)]]

[graph jacobi_sc]

[endsect] [/section:jacobi_sc Jacobi Elliptic Function sc]

[section:jacobi_sd Jacobi Elliptic Function sd]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_sd(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_sd(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['sd].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic, with:

[expression ['sd(u, k) = sn(u, k) / dn(u, k)]]

[graph jacobi_sd]

[endsect] [/section:jacobi_sd Jacobi Elliptic Function sd]

[section:jacobi_sn Jacobi Elliptic Function sn]

[heading Synopsis]

``
  #include <boost/math/special_functions/jacobi_elliptic.hpp>
``

  namespace boost { namespace math {

   template <class T, class U>
   ``__sf_result`` jacobi_sn(T k, U u);

   template <class T, class U, class Policy>
   ``__sf_result`` jacobi_sn(T k, U u, const Policy& pol);

  }} // namespaces
  
[heading Description]

This function returns the Jacobi elliptic function ['sn].

[optional_policy]

This function is a trivial wrapper around __jacobi_elliptic.

[graph jacobi_sn]

[endsect] [/section:jacobi_sn Jacobi Elliptic Function sn]

[endsect] [/section:jacobi Jacobi Elliptic Functions]