Skip to content

Commit 1363c08

Browse files
authored
Merge pull request #45 from ajt60gaibb/support-0.6
WIP: Support 0.6
2 parents 43a31d6 + 51834b5 commit 1363c08

16 files changed

+206
-188
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ os:
33
- linux
44
- osx
55
julia:
6-
- 0.4
76
- 0.5
87
- nightly
98
notifications:

REQUIRE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
julia 0.4
1+
julia 0.5
22
Compat 0.8.8
3+
SpecialFunctions 0.1

src/FastGaussQuadrature.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module FastGaussQuadrature
22

3-
using Compat
3+
using Compat, SpecialFunctions
44

55
export gausslegendre
66
export gausschebyshev
@@ -11,6 +11,8 @@ export gausslobatto
1111
export gaussradau
1212
export besselroots
1313

14+
import SpecialFunctions: besselj, airyai, airyaiprime
15+
1416
include("gausslegendre.jl")
1517
include("gausschebyshev.jl")
1618
include("gausslaguerre.jl")

src/besselroots.jl

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function besselroots(nu::Float64, n::Int64)
1+
function besselroots(nu::Float64, n::Int64)
22
#BESSELROOTS The first N roots of the function J_v(x)
33

44
# DEVELOPERS NOTES:
@@ -10,17 +10,17 @@ function besselroots(nu::Float64, n::Int64)
1010
# V > 5 --> moderately accurate for the 6 first zeros and good
1111
# approximations for the others (McMahon's expansion)
1212

13-
# This code was originally written by L. L. Peixoto in MATLAB.
13+
# This code was originally written by L. L. Peixoto in MATLAB.
1414
# Later modified by A. Townsend to work in Julia
15-
15+
1616
if ( n == 0 )
1717
x = []
1818
elseif( n > 0 && nu == 0 )
1919
x = McMahon( nu, n )
2020
correctFirstFew = Tabulate( )
2121
x[1:min(n,20)] = correctFirstFew[1:min(n,20)]
2222
x
23-
elseif ( n>0 && nu >= -1 && nu <= 5 )
23+
elseif ( n>0 && nu >= -1 && nu <= 5 )
2424
x = McMahon( nu, n )
2525
correctFirstFew = Piessens( nu )
2626
x[1:min(n,6)] = correctFirstFew[1:min(n,6)]
@@ -33,55 +33,55 @@ end
3333

3434

3535
function McMahon( nu::Float64, n::Int64 )
36-
# McMahon's expansion. This expansion gives very accurate approximation
37-
# for the sth zero (s >= 7) in the whole region V >=- 1, and moderate
38-
# approximation in other cases.
39-
b = Array(Float64,n)
40-
mu = 4*nu^2
41-
a1 = 1. / 8.
42-
a3 = (7.*mu-31.) / 384.
43-
a5 = 4.*(3779.+mu*(-982.+83.*mu)) / 61440. # Evaluate via Horner's method.
44-
a7 = 6.*(-6277237.+mu*(1585743.+mu*(-153855.+6949.*mu))) / 20643840.;
45-
a9 = 144.*(2092163573.+mu*(-512062548.+mu*(48010494.+mu*(-2479316.+70197.*mu)))) / 11890851840.
46-
a11 = 720.*(-8249725736393.+mu*(1982611456181.+mu*(-179289628602.+mu*(8903961290. +
47-
mu*(-287149133.+5592657.*mu))))) / 10463949619200.
48-
a13 = 576.*(423748443625564327. + mu*(-100847472093088506.+mu*(8929489333108377. +
49-
mu*(-426353946885548.+mu*(13172003634537.+mu*(-291245357370. + mu*4148944183.)))))) / 13059009124761600.
50-
for k=1:n b[k] = .25*(2*nu+4*k-1)*pi end # beta
51-
# Evaluate using Horner's scheme:
52-
x = b - (mu-1)*( ((((((a13./b.^2 + a11)./b.^2 + a9)./b.^2 + a7)./b.^2 + a5)./b.^2 + a3)./b.^2 + a1)./b)
36+
# McMahon's expansion. This expansion gives very accurate approximation
37+
# for the sth zero (s >= 7) in the whole region V >=- 1, and moderate
38+
# approximation in other cases.
39+
b = Array{Float64}(n)
40+
mu = 4*nu^2
41+
a1 = 1. / 8.
42+
a3 = (7.*mu-31.) / 384.
43+
a5 = 4.*(3779.+mu*(-982.+83.*mu)) / 61440. # Evaluate via Horner's method.
44+
a7 = 6.*(-6277237.+mu*(1585743.+mu*(-153855.+6949.*mu))) / 20643840.;
45+
a9 = 144.*(2092163573.+mu*(-512062548.+mu*(48010494.+mu*(-2479316.+70197.*mu)))) / 11890851840.
46+
a11 = 720.*(-8249725736393.+mu*(1982611456181.+mu*(-179289628602.+mu*(8903961290. +
47+
mu*(-287149133.+5592657.*mu))))) / 10463949619200.
48+
a13 = 576.*(423748443625564327. + mu*(-100847472093088506.+mu*(8929489333108377. +
49+
mu*(-426353946885548.+mu*(13172003634537.+mu*(-291245357370. + mu*4148944183.)))))) / 13059009124761600.
50+
for k=1:n b[k] = .25*(2*nu+4*k-1)*pi end # beta
51+
# Evaluate using Horner's scheme:
52+
x = b - (mu-1)*( ((((((a13./b.^2 + a11)./b.^2 + a9)./b.^2 + a7)./b.^2 + a5)./b.^2 + a3)./b.^2 + a1)./b)
5353
end
5454

5555

5656
function Tabulate( )
57-
# First 20 roots of J0(x) are precomputed (using Wolfram Alpha):
58-
y = Array(Float64,20)
59-
y = [ 2.4048255576957728
60-
5.5200781102863106
61-
8.6537279129110122
62-
11.791534439014281
63-
14.930917708487785
64-
18.071063967910922
65-
21.211636629879258
66-
24.352471530749302
67-
27.493479132040254
68-
30.634606468431975
69-
33.775820213573568
70-
36.917098353664044
71-
40.058425764628239
72-
43.199791713176730
73-
46.341188371661814
74-
49.482609897397817
75-
52.624051841114996
76-
55.765510755019979
77-
58.906983926080942
78-
62.048469190227170 ]
57+
# First 20 roots of J0(x) are precomputed (using Wolfram Alpha):
58+
y = Array{Float64}(20)
59+
y = [ 2.4048255576957728
60+
5.5200781102863106
61+
8.6537279129110122
62+
11.791534439014281
63+
14.930917708487785
64+
18.071063967910922
65+
21.211636629879258
66+
24.352471530749302
67+
27.493479132040254
68+
30.634606468431975
69+
33.775820213573568
70+
36.917098353664044
71+
40.058425764628239
72+
43.199791713176730
73+
46.341188371661814
74+
49.482609897397817
75+
52.624051841114996
76+
55.765510755019979
77+
58.906983926080942
78+
62.048469190227170 ]
7979
end
8080

81-
function Piessens( nu::Float64 )
82-
# Piessens's Chebyshev series approximations (1984). Calculates the 6 first
83-
# zeros to at least 12 decimal figures in region -1 <= V <= 5:
84-
y = Array(Float64,6);
81+
function Piessens( nu::Float64 )
82+
# Piessens's Chebyshev series approximations (1984). Calculates the 6 first
83+
# zeros to at least 12 decimal figures in region -1 <= V <= 5:
84+
y = Array{Float64}(6);
8585

8686
C = [
8787
2.883975316228 8.263194332307 11.493871452173 14.689036505931 17.866882871378 21.034784308088
@@ -114,8 +114,8 @@ function Piessens( nu::Float64 )
114114
0.000000000008 0.000000000011 0. 0. 0. 0.
115115
-0.000000000003 -0.000000000005 0. 0. 0. 0.
116116
0.000000000001 0.000000000002 0. 0. 0. 0.]
117-
118-
T = Array(Float64,size(C,1))
117+
118+
T = Array{Float64}(size(C,1))
119119
pt = (nu-2)/3
120120
T[1], T[2] = 1., pt
121121
for k = 2:size(C,1)-1
@@ -124,4 +124,4 @@ function Piessens( nu::Float64 )
124124
y[1:6] = T'*C;
125125
y[1] *= sqrt(nu+1); # Scale the first root.
126126
y
127-
end
127+
end

src/gausshermite.jl

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ function hermpts_asy( n::Int )
3939

4040
x0 = HermiteInitialGuesses( n ) # get initial guesses
4141
t0 = x0./sqrt(2n+1)
42-
theta0 = acos(t0) # convert to theta-variable
42+
theta0 = acos.(t0) # convert to theta-variable
4343
val = x0;
4444
for k = 1:20
4545
val = hermpoly_asy_airy(n, theta0);
46-
dt = -val[1]./(sqrt(2)*sqrt(2n+1)*val[2].*sin(theta0))
47-
theta0 = theta0 - dt; # Newton update
46+
dt = -val[1]./(sqrt(2).*sqrt(2n+1).*val[2].*sin.(theta0))
47+
theta0 .-= dt; # Newton update
4848
if norm(dt,Inf) < sqrt(eps(Float64))/10
4949
break
5050
end
5151
end
52-
t0 = cos(theta0)
52+
t0 = cos.(theta0)
5353
x = sqrt(2n+1)*t0 #back to x-variable
54-
ders = x.*val[1] + sqrt(2)*val[2]
55-
w = (exp(-x.^2)./ders.^2)'; # quadrature weights
54+
ders = x.*val[1] .+ sqrt(2).*val[2]
55+
w = exp.(-x.^2)./ders.^2; # quadrature weights
5656

5757
x = (x, w)
5858
end
@@ -66,14 +66,14 @@ val = x0
6666
for kk = 1:10
6767
val = hermpoly_rec(n, x0)
6868
dx = val[1]./val[2]
69-
dx[ isnan( dx ) ] = 0
69+
dx[ isnan.( dx ) ] = 0
7070
x0 = x0 - dx
7171
if norm(dx, Inf)<sqrt(eps(Float64))
7272
break
7373
end
7474
end
7575
x = x0/sqrt(2)
76-
w = exp(-x.^2)./val[2].^2 # quadrature weights
76+
w = exp.((-).(x.^2))./val[2].^2 # quadrature weights
7777

7878
x = (x, w)
7979
end
@@ -82,8 +82,8 @@ function hermpoly_rec( n::Int, x0)
8282
# HERMPOLY_rec evaluation of scaled Hermite poly using recurrence
8383

8484
# evaluate:
85-
Hold = exp(-x0.^2/4)
86-
H = x0.*exp(-x0.^2/4)
85+
Hold = exp.(x0.^2./(-4))
86+
H = x0.*exp.(x0.^2./(-4))
8787
for k = 1:n-1
8888
Hold, H = H, (x0.*H./sqrt(k+1) - Hold./sqrt(1+1/k))
8989
end
@@ -97,15 +97,15 @@ function hermpoly_asy_airy(n::Int, theta)
9797
# theta-space.
9898

9999
musq = 2n+1;
100-
cosT = cos(theta)
101-
sinT = sin(theta)
102-
sin2T = 2*cosT.*sinT
103-
eta = .5*theta - .25*sin2T
100+
cosT = cos.(theta)
101+
sinT = sin.(theta)
102+
sin2T = 2.*cosT.*sinT
103+
eta = 0.5.*theta .- 0.25.*sin2T
104104
chi = -(3*eta/2).^(2/3)
105105
phi = (-chi./sinT.^2).^(1/4)
106106
C = 2*sqrt(pi)*musq^(1/6)*phi
107-
Airy0 = real(airy(musq.^(2/3)*chi))
108-
Airy1 = real(airy(1,musq.^(2/3)*chi))
107+
Airy0 = real.(airyai.(musq.^(2/3).*chi))
108+
Airy1 = real.(airyaiprime.(musq.^(2/3).*chi))
109109

110110
# Terms in (12.10.43):
111111
a0 = 1; b0 = 1
@@ -179,9 +179,9 @@ function HermiteInitialGuesses( n::Int )
179179
# [2] F. G. Tricomi, Sugli zeri delle funzioni di cui si conosce una
180180
# rappresentazione asintotica, Ann. Mat. Pura Appl. 26 (1947), pp. 283-300.
181181

182-
# Error if n < 20 because initial guesses are based on asymptotic expansions:
183-
@assert n>=20
184-
182+
# Error if n < 20 because initial guesses are based on asymptotic expansions:
183+
@assert n>=20
184+
185185
# Gatteschi formula involving airy roots [1].
186186
# These initial guess are good near x = sqrt(n+1/2);
187187
if mod(n,2) == 1
@@ -209,9 +209,9 @@ airyrts_exact = [-2.338107410459762 # Exact Airy roots.
209209
-12.828776752865757]
210210
airyrts[1:10] = airyrts_exact # correct first 10.
211211

212-
x_init = sqrt(abs(nu + 2^(2/3)*airyrts*nu^(1/3) + 1/5*2^(4/3)*airyrts.^2*nu^(-1/3) +
213-
(11/35-a^2-12/175*airyrts.^3)/nu + (16/1575*airyrts+92/7875*airyrts.^4)*2^(2/3)*nu^(-5/3) -
214-
(15152/3031875*airyrts.^5+1088/121275*airyrts.^2)*2^(1/3)*nu^(-7/3)))
212+
x_init = sqrt.(abs.(nu .+ (2^(2/3)).*airyrts.*nu^(1/3) .+ (1/5*2^(4/3)).*airyrts.^2.*nu^(-1/3) .+
213+
(11/35-a^2-12/175).*airyrts.^3./nu .+ ((16/1575).*airyrts.+(92/7875).*airyrts.^4).*2^(2/3).*nu^(-5/3) .-
214+
((15152/3031875).*airyrts.^5.+(1088/121275).*airyrts.^2).*2^(1/3).*nu^(-7/3)))
215215
x_init_airy = real( flipdim(x_init,1) )
216216

217217
# Tricomi initial guesses. Equation (2.1) in [1]. Originally in [2].
@@ -223,14 +223,14 @@ nu = (4*m+2*a+2)
223223
rhs = (4*m-4*collect(1:m)+3)./nu*pi
224224

225225
for k = 1:7
226-
val = Tnk0 - sin(Tnk0) - rhs
227-
dval = 1 - cos(Tnk0)
226+
val = Tnk0 .- sin.(Tnk0) .- rhs
227+
dval = 1 .- cos.(Tnk0)
228228
dTnk0 = val./dval
229-
Tnk0 = Tnk0 - dTnk0
229+
Tnk0 = Tnk0 .- dTnk0
230230
end
231231

232-
tnk = cos(Tnk0/2).^2
233-
x_init_sin = sqrt(nu*tnk - (5./(4*(1-tnk).^2) - 1./(1-tnk)-1+3*a^2)/3/nu)
232+
tnk = cos.(Tnk0./2).^2
233+
x_init_sin = sqrt.(nu*tnk .- (5./(4.*(1-tnk).^2) .- 1./(1.-tnk).-1.+3*a^2)./3./nu)
234234

235235
# Patch together
236236
p = 0.4985+eps(Float64)
@@ -251,7 +251,7 @@ end
251251
function hermpts_gw( n::Int )
252252
# Golub--Welsch algorithm. Used here for n<=20.
253253

254-
beta = sqrt(.5*(1:n-1)) # 3-term recurrence coeffs
254+
beta = sqrt.(0.5.*(1:n-1)) # 3-term recurrence coeffs
255255
T = diagm(beta, 1) + diagm(beta, -1) # Jacobi matrix
256256
(D, V) = eig(T) # Eigenvalue decomposition
257257
indx = sortperm(D) # Hermite points
@@ -263,4 +263,4 @@ function hermpts_gw( n::Int )
263263
x = x[ii]
264264
w = w[ii]
265265
return (x,w)
266-
end
266+
end

0 commit comments

Comments
 (0)