Skip to content

Commit b72e80f

Browse files
cgeogaheltonmc
andauthored
Update src/besselk.jl
Co-authored-by: Michael Helton <[email protected]>
1 parent 5abdbd0 commit b72e80f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/besselk.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,29 @@ end
462462
# function, which would either need to be lifted from SpecialFunctions.jl or
463463
# re-implemented. And with an order of, like, 10, this seems to be pretty
464464
# accurate and still faster than the uniform asymptotic expansion.
465-
function _besselk_as_pair(v, x::T, order) where{T}
465+
function _besselk_as_pair(v, x::T, order) where T
466+
fv = 4*v*v
467+
fvp1 = 4*(v+one(v))^2
468+
z = 8*x
469+
knu, knpu1 = one(T), one(T)
470+
ak_nu = fv - 1
471+
ak_nup1 = fvp1 - 1
472+
473+
for i in 1:order
474+
term_v = ak_nu / z
475+
term_vp1 = ak_nup1 / z
476+
knu += term_v
477+
knpu1 += term_vp1
478+
479+
a = muladd(2, i, one(T))^2
480+
z *= 8*x*(i + one(T))
481+
482+
ak_nu *= fv - a
483+
ak_nup1 *= fvp1 - a
484+
end
485+
coef = SQRT_PID2(T)*exp(-x)/sqrt(x)
486+
return coef*knu, coef*knpu1
487+
end
466488
fv = 4*v*v
467489
fvp1 = 4*(v+one(v))^2
468490
_z = x

0 commit comments

Comments
 (0)