Skip to content

Commit 02a9d7a

Browse files
committed
add an example in the readme
1 parent 5aab92f commit 02a9d7a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,46 @@ julia> besselk0(x)
120120
julia> besselk1(x)
121121
1.6750295538365835e-6
122122
```
123+
## Support for sequence of orders
124+
125+
We also provide support for `besselj(nu::M, x::T)`, `bessely(nu::M, x::T)`, `besseli(nu::M, x::T)`, `besselk(nu::M, x::T)`, `besseli(nu::M, x::T)`, `besselh(nu::M, k, x::T)` when `M` is some `AbstractRange` and `T` is some float.
126+
127+
```julia
128+
julia> besselj(0:10, 1.0)
129+
11-element Vector{Float64}:
130+
0.7651976865579666
131+
0.44005058574493355
132+
0.11490348493190049
133+
0.019563353982668407
134+
0.0024766389641099553
135+
0.00024975773021123444
136+
2.0938338002389273e-5
137+
1.5023258174368085e-6
138+
9.422344172604502e-8
139+
5.249250179911876e-9
140+
2.630615123687453e-10
141+
```
142+
143+
In general, this provides a fast way to generate a sequence of Bessel functions for many orders.
144+
```julia
145+
julia> @btime besselj(0:100, 50.0)
146+
443.328 ns (2 allocations: 1.75 KiB)
147+
```
148+
This function will allocate so it is recommended that you calculate the Bessel functions at the top level of your function outside any hot loop. For example,
149+
150+
```julia
151+
function bessel_sequence(x, orders)
152+
J_nu = besselj(orders, x)
153+
out = zero(x)
154+
for i in eachindex(J_nu)
155+
out += sin(x*i)*J_nu[i]
156+
end
157+
return out
158+
end
159+
160+
julia> bessel_sequence(10.2, 1:400)
161+
0.11404996570230919
162+
```
123163

124164
### Support for negative arguments
125165

0 commit comments

Comments
 (0)