@@ -27,7 +27,7 @@ immutable TracyWidom <: ContinuousUnivariateDistribution end
2727Probability density function of the Tracy-Widom distribution
2828
2929Computes the Tracy-Widom distribution by directly solving the
30- Painlevé II equation using the ode23 numerical integrator
30+ Painlevé II equation using the Vern8 numerical integrator
3131
3232# Arguments
3333* `d::TracyWidom` or `Type{TracyWidom}`: an instance of `TracyWidom` or the type itself
@@ -38,39 +38,43 @@ function pdf{S<:Real}(d::TracyWidom, t::S, t0::S = convert(S, -8.0))
3838 t≤ t0 && return 0.0
3939 t≥ 5 && return 0.0
4040
41- ts, y = _solve_painleve_ii (t0, t)
41+ sol = _solve_painleve_ii (t0, t)
4242
43- ΔF2= exp (- y [end - 1 ][3 ]) - exp (- y [end ][3 ]) # the cumulative distribution
44- f2= ΔF2/ (ts [end ]- ts [end - 1 ]) # the density at t
43+ ΔF2= exp (- sol [end - 1 ][3 ]) - exp (- sol [end ][3 ]) # the cumulative distribution
44+ f2= ΔF2/ (sol . t [end ]- sol . t [end - 1 ]) # the density at t
4545end
4646pdf (d:: Type{TracyWidom} , t:: Real ) = pdf (d (), t)
4747
4848"""
4949Cumulative density function of the Tracy-Widom distribution
5050
5151Computes the Tracy-Widom distribution by directly solving the
52- Painlevé II equation using the ode23 numerical integrator
52+ Painlevé II equation using the Vern8 numerical integrator
5353
5454See `pdf(::TracyWidom)` for a description of the arguments.
5555"""
5656function cdf {S<:Real} (d:: TracyWidom , t:: S , t0:: S = convert (S, - 8.0 ))
5757 t≤ t0 && return 0.0
5858 t≥ 5 && return 1.0
59-
60- ts, y = _solve_painleve_ii (t0, t)
61-
62- F2= exp (- y[end ][3 ])
59+ sol = _solve_painleve_ii (t0, t)
60+ F2= exp (- sol[end ][3 ])
6361end
6462cdf (d:: Type{TracyWidom} , t:: Real ) = cdf (d (), t)
6563
6664# An internal function which sets up the Painleve II differential equation and
67- # runs it through the ode23 numerical integrator
65+ # runs it through the Vern8 numerical integrator
6866function _solve_painleve_ii {S<:Real} (t0:: S , t:: S )
69- deq (t, y) = [y[2 ], t* y[1 ]+ 2 y[1 ]^ 3 , y[4 ], y[1 ]^ 2 ]
67+ function deq (t, y, dy)
68+ dy[1 ] = y[2 ]
69+ dy[2 ] = t* y[1 ]+ 2 y[1 ]^ 3
70+ dy[3 ] = y[4 ]
71+ dy[4 ] = y[1 ]^ 2
72+ end
7073 a0 = airy (t0)
71- T = typeof (a0 )
74+ T = typeof (big (a0) )
7275 y0= T[a0, airy (1 , t0), 0 , airy (t0)^ 2 ] # Initial conditions
73- (ts, y)= ode23 (deq, y0, [t0, t]) # Solve the ODE
76+ prob = ODEProblem (deq,y0,(t0,t))
77+ solve (prob, Vern8 (), abstol= 1e-12 , reltol= 1e-12 ) # Solve the ODE
7478end
7579
7680"""
0 commit comments