Skip to content

Commit e6ba1d5

Browse files
authored
Merge pull request #30 from ChrisRackauckas/diffeq
Switch to DifferentialEquations.jl
2 parents 6fdccbf + a9a89f3 commit e6ba1d5

File tree

7 files changed

+36
-27
lines changed

7 files changed

+36
-27
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ addons:
66
os:
77
- linux
88
julia:
9-
- 0.4
109
- 0.5
1110
- nightly
1211
sudo: false
@@ -17,4 +16,3 @@ notifications:
1716
# - julia -e 'Pkg.clone(pwd()); Pkg.build("RandomMatrices"); Pkg.test("RandomMatrices"; coverage=true)'
1817
after_success:
1918
- julia -e 'Pkg.add("Coverage"); cd(Pkg.dir("RandomMatrices")); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'
20-

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ RandomMatrices.jl
33

44
Random matrix package for [Julia](http://julialang.org).
55

6-
[![RandomMatrices](http://pkg.julialang.org/badges/RandomMatrices_0.4.svg)](http://pkg.julialang.org/?pkg=RandomMatrices)
6+
[![RandomMatrices](http://pkg.julialang.org/badges/RandomMatrices_0.5.svg)](http://pkg.julialang.org/?pkg=RandomMatrices)
77
[![Build Status](https://travis-ci.org/jiahao/RandomMatrices.jl.png?branch=master)](https://travis-ci.org/jiahao/RandomMatrices.jl)
88
[![Coverage Status](https://coveralls.io/repos/jiahao/RandomMatrices.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/jiahao/RandomMatrices.jl?branch=master)
99
[![codecov.io](https://codecov.io/github/jiahao/RandomMatrices.jl/coverage.svg?branch=master)](https://codecov.io/github/jiahao/RandomMatrices.jl?branch=master)

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
julia 0.4
1+
julia 0.5
22
Combinatorics 0.2
33
Distributions 0.8.10
4-
ODE 0.2.1
4+
OrdinaryDiffEq
55
GSL 0.3.1
66
Compat 0.9.2

demos/book/8/randomgrowth2.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#randomgrowth2.jl
22
using PyPlot
3-
using ODE
3+
using OrdinaryDiffEq
44

55
function randomgrowth2()
66
num_trials = 2000
@@ -32,16 +32,22 @@ function randomgrowth2()
3232
t0 = 4
3333
tn = -6
3434
dx = 0.005
35-
deq = (t, y) -> [y[2]; t*y[1]+2*y[1]^3; y[4]; y[1]^2]
36-
y0 = [airy(t0); airy(1,t0); 0; airy(t0)^2] # boundary conditions
37-
t, y = ode23(deq, y0, t0:-dx:tn) # solve
38-
F2 = Float64[exp(-y[i][3]) for i = 1:length(y)] # the distribution
39-
f2 = gradient(F2, t) # the density
35+
deq = function (t, y, dy)
36+
dy[1] = y[2]
37+
dy[2] = t*y[1]+2y[1]^3
38+
dy[3] = y[4]
39+
dy[4] = y[1]^2
40+
end
41+
y0 = big.([airy(t0); airy(1,t0); 0; airy(t0)^2]) # boundary conditions
42+
prob = ODEProblem(deq,y0,(t0,tn))
43+
sol = solve(prob,Vern8(), saveat=-dx, abstol=1e-12, reltol=1e-12) # solve
44+
F2 = Float64[exp(-sol[i][3]) for i = 1:length(y)] # the distribution
45+
f2 = gradient(F2, t) # the density
4046

4147
# add(p, Curve(t, f2, "color", "red", "linewidth", 3))
4248
# Winston.display(p)
4349
subplot(1,length(Ns),jj)
44-
plot(t, f2, "r", linewidth = 3)
50+
plot(sol.t, f2, "r", linewidth = 3)
4551
ylim(0, 0.6)
4652
println(mean(C))
4753
end

src/RandomMatrices.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module RandomMatrices
33
using Combinatorics
44
using Compat
55
using GSL
6-
using ODE
6+
using OrdinaryDiffEq
7+
using DiffEqBase # This line is only needed on v0.5, and comes free from OrdinaryDiffEq on v0.6
78

89
import Base: isinf, rand
910
import Distributions: ContinuousUnivariateDistribution,

src/densities/TracyWidom.jl

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ immutable TracyWidom <: ContinuousUnivariateDistribution end
2727
Probability density function of the Tracy-Widom distribution
2828
2929
Computes 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
tt0 && return 0.0
3939
t5 && 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
4545
end
4646
pdf(d::Type{TracyWidom}, t::Real) = pdf(d(), t)
4747

4848
"""
4949
Cumulative density function of the Tracy-Widom distribution
5050
5151
Computes 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
5454
See `pdf(::TracyWidom)` for a description of the arguments.
5555
"""
5656
function cdf{S<:Real}(d::TracyWidom, t::S, t0::S = convert(S, -8.0))
5757
tt0 && return 0.0
5858
t5 && 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])
6361
end
6462
cdf(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
6866
function _solve_painleve_ii{S<:Real}(t0::S, t::S)
69-
deq(t, y) = [y[2], t*y[1]+2y[1]^3, y[4], y[1]^2]
67+
function deq(t, y, dy)
68+
dy[1] = y[2]
69+
dy[2] = t*y[1]+2y[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
7478
end
7579

7680
"""

test/densities/TracyWidom.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using Base.Test
77
@test cdf(TracyWidom, -10) == 0
88
@test cdf(TracyWidom, 10) == 1
99

10-
if isdefined(:ODE) && isa(ODE, Module)
10+
if isdefined(:OrdinaryDiffEq) && isa(OrdinaryDiffEq, Module)
1111
t = rand()
1212
@test pdf(TracyWidom, t) > 0
1313
@test 0 < cdf(TracyWidom, t) < 1

0 commit comments

Comments
 (0)