You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
n \frac{d^{(n-1)} P_{\ell-1}(x)}{dx^{(n-1)}} \right) - \frac{(\ell-1)}{\ell} \frac{d^n P_{\ell-2}(x)}{dx^n}
16
+
```
17
+
18
+
This provides a simultaneous recursion relation in ``\ell`` as well as ``n``, solving which we may obtain derivatives up to any order. This is the approach used in this package to compute the derivatives of Legendre polynomials.
19
+
20
+
## Automatic diferentiation
21
+
3
22
The Julia automatic differentiation framework may be used to compute the derivatives of Legendre polynomials alongside their values. Since the defintions of the polynomials are completely general, they may be called with dual or hyperdual numbers as arguments to evaluate derivarives in one go.
4
23
We demonstrate one example of this using the package [`HyperDualNumbers.jl`](https://github.com/JuliaDiff/HyperDualNumbers.jl) v4:
5
24
6
25
```@meta
7
26
DocTestSetup = quote
8
27
using LegendrePolynomials
28
+
using HyperDualNumbers
9
29
end
10
30
```
11
31
@@ -84,51 +104,4 @@ Pl_dPl_d2Pl (generic function with 1 method)
We may therefore compute the second derivative from the function and its first derivative. Higher derivatives may further be computed in terms of the lower ones.
104
-
105
-
We demonstrate the second-derivative computation using the package [`DualNumbers.jl`](https://github.com/JuliaDiff/DualNumbers.jl) v0.5:
Copy file name to clipboardExpand all lines: docs/src/index.md
+35-3Lines changed: 35 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ end
7
7
8
8
# Introduction
9
9
10
-
Compute [Legendre polynomials](https://en.wikipedia.org/wiki/Legendre_polynomials) using a 3-term recursion relation (Bonnet’s recursion formula).
10
+
Compute [Legendre polynomials](https://en.wikipedia.org/wiki/Legendre_polynomials)and their derivatives using a 3-term recursion relation (Bonnet’s recursion formula).
11
11
12
12
```math
13
13
P_\ell(x) = \left((2\ell-1) x P_{\ell-1}(x) - (\ell-1)P_{\ell - 2}(x)\right)/\ell
@@ -19,10 +19,12 @@ Currently this package evaluates the standard polynomials that satisfy ``P_\ell(
*[`Pl(x,l)`](@ref Pl): this evaluates the Legendre polynomial for a given degree `l` at the argument `x`. The argument needs to satisfy `-1 <= x <= 1`.
25
25
*[`collectPl(x; lmax)`](@ref collectPl): this evaluates all the polynomials for `l` lying in `0:lmax` at the argument `x`. As before the argument needs to lie in the domain of validity. Functionally this is equivalent to `Pl.(x, 0:lmax)`, except `collectPl` evaluates the result in one pass, and is therefore faster. There is also the in-place version [`collectPl!`](@ref) that uses a pre-allocated array.
26
+
*[`dnPl(x, l, n)`](@ref dnPl): this evaluates the ``n``-th derivative of the Legendre polynomial ``P_\ell(x)`` at the argument ``x``. The argument needs to satisfy `-1 <= x <= 1`.
27
+
*[`collectdnPl(x; n, lmax)`](@ref collectdnPl): this evaluates the ``n``-th derivative of all the Legendre polynomials for `l = 0:lmax`. There is also an in-place version [`collectdnPl!`](@ref) that uses a pre-allocated array.
26
28
27
29
# Quick Start
28
30
@@ -33,7 +35,14 @@ julia> Pl(0.5, 3)
33
35
-0.4375
34
36
```
35
37
36
-
Evaluate all the polynomials for `l` in `0:lmax` as
38
+
Evaluate the `n`th derivative for one `l` as `dnPl(x, l, n)`:
39
+
40
+
```jldoctest
41
+
julia> dnPl(0.5, 3, 2)
42
+
7.5
43
+
```
44
+
45
+
Evaluate all the polynomials for `l` in `0:lmax` as `collectPl(x; lmax)`
0 commit comments