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
16
```
17
17
18
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
19
20
20
## Automatic diferentiation
21
21
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.
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.
23
23
We demonstrate one example of this using the package [`HyperDualNumbers.jl`](https://github.com/JuliaDiff/HyperDualNumbers.jl) v4:
24
24
25
25
```@meta
@@ -43,21 +43,21 @@ julia> p = Pl(xh, 3)
43
43
-0.4375 + 0.375ε₁ + 0.375ε₂ + 7.5ε₁ε₂
44
44
```
45
45
46
-
The Legendre polynomial ``P_\ell(x)`` may be obtained using
46
+
The Legendre polynomial ``P_\ell(x)`` may be obtained using
47
47
48
48
```jldoctest hyperdual
49
49
julia> realpart(p)
50
50
-0.4375
51
51
```
52
52
53
-
The first derivative ``dP_\ell(x)/dx`` may be obtained as
53
+
The first derivative ``dP_\ell(x)/dx`` may be obtained as
54
54
55
55
```jldoctest hyperdual
56
56
julia> ε₁part(p)
57
57
0.375
58
58
```
59
59
60
-
The second derivative ``d^2P_\ell(x)/dx^2`` may be obtained using
60
+
The second derivative ``d^2P_\ell(x)/dx^2`` may be obtained using
61
61
62
62
```jldoctest hyperdual
63
63
julia> ε₁ε₂part(p)
@@ -68,7 +68,7 @@ Something similar may also be evaluated for all `l` iteratively. For example, th
68
68
69
69
```jldoctest hyperdual
70
70
julia> collectPl(xh, lmax=4)
71
-
5-element OffsetArray(::Array{Hyper{Float64},1}, 0:4) with eltype Hyper{Float64} with indices 0:4:
71
+
5-element OffsetArray(::Vector{Hyper{Float64}}, 0:4) with eltype Hyper{Float64} with indices 0:4:
72
72
1.0 + 0.0ε₁ + 0.0ε₂ + 0.0ε₁ε₂
73
73
0.5 + 1.0ε₁ + 1.0ε₂ + 0.0ε₁ε₂
74
74
-0.125 + 1.5ε₁ + 1.5ε₂ + 3.0ε₁ε₂
@@ -80,15 +80,15 @@ We may extract the first derivatives by broadcasting the function `ε₁part` on
80
80
81
81
```jldoctest hyperdual
82
82
julia> ε₁part.(collectPl(xh, lmax=4))
83
-
5-element OffsetArray(::Array{Float64,1}, 0:4) with eltype Float64 with indices 0:4:
83
+
5-element OffsetArray(::Vector{Float64}, 0:4) with eltype Float64 with indices 0:4:
84
84
0.0
85
85
1.0
86
86
1.5
87
87
0.375
88
88
-1.5625
89
89
```
90
90
91
-
Similarly the function `ε₁ε₂part` may be used to obtain the second derivatives.
91
+
Similarly the function `ε₁ε₂part` may be used to obtain the second derivatives.
92
92
93
93
Several convenience functions to compute the derivatives of Legendre polynomials were available in `LegendrePolynomials` v0.2, but have been removed in v0.3. The users are encouraged to implement convenience functions to extract the derivatives as necessary. As an exmaple, we may compute the polynomials and their first and second derivatives together as
94
94
@@ -104,4 +104,4 @@ Pl_dPl_d2Pl (generic function with 1 method)
*[`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.
@@ -46,7 +46,7 @@ Evaluate all the polynomials for `l` in `0:lmax` as `collectPl(x; lmax)`
46
46
47
47
```jldoctest
48
48
julia> collectPl(0.5, lmax = 3)
49
-
4-element OffsetArray(::Array{Float64,1}, 0:3) with eltype Float64 with indices 0:3:
49
+
4-element OffsetArray(::Vector{Float64}, 0:3) with eltype Float64 with indices 0:3:
50
50
1.0
51
51
0.5
52
52
-0.125
@@ -57,7 +57,7 @@ Evaluate all the `n`th derivatives as `collectdnPl(x; lmax, n)`:
57
57
58
58
```jldoctest
59
59
julia> collectdnPl(0.5, lmax = 5, n = 3)
60
-
6-element OffsetArray(::Array{Float64,1}, 0:5) with eltype Float64 with indices 0:5:
60
+
6-element OffsetArray(::Vector{Float64}, 0:5) with eltype Float64 with indices 0:5:
0 commit comments