Skip to content

Commit 4efd06f

Browse files
author
fchen121
committed
Improve test cases
1 parent 970b404 commit 4efd06f

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

test/fractional_to_ordinary.jl

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using Test
77
@variables x(t)
88
D = Differential(t)
99
tspan = (0., 1.)
10+
timepoint = [0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.]
1011

1112
function expect(t, α)
1213
return (3/2*t^/2) - t^4)^2
@@ -18,7 +19,7 @@ eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^(α/2)-t^4)^3 - x^(3/2)
1819
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1)
1920

2021
prob = ODEProblem(sys, [], tspan)
21-
sol = solve(prob, radau5(), abstol = 1e-10, reltol = 1e-10)
22+
sol = solve(prob, radau5(), saveat=timepoint, abstol = 1e-10, reltol = 1e-10)
2223

2324
time = 0
2425
while(time <= 1)
@@ -32,11 +33,11 @@ eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^(α/2)-t^4)^3 - x^(3/2)
3233
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1)
3334

3435
prob = ODEProblem(sys, [], tspan)
35-
sol = solve(prob, radau5(), abstol = 1e-10, reltol = 1e-10)
36+
sol = solve(prob, radau5(), saveat=timepoint, abstol = 1e-10, reltol = 1e-10)
3637

3738
time = 0
3839
while(time <= 1)
39-
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-3)
40+
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-7)
4041
time += 0.1
4142
end
4243

@@ -46,11 +47,11 @@ eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^(α/2)-t^4)^3 - x^(3/2)
4647
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1)
4748

4849
prob = ODEProblem(sys, [], tspan)
49-
sol = solve(prob, radau5(), abstol = 1e-10, reltol = 1e-10)
50+
sol = solve(prob, radau5(), saveat=timepoint, abstol = 1e-10, reltol = 1e-10)
5051

5152
time = 0
5253
while(time <= 1)
53-
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-3)
54+
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-7)
5455
time += 0.1
5556
end
5657

@@ -60,9 +61,25 @@ end
6061
D = Differential(t)
6162
tspan = (0., 220.)
6263

63-
sys = fractional_to_ordinary([1 - 4*x + x^2 * y, 3*x - x^2 * y], [x, y], [1.3, 0.8], 10^-6, 220; initials=[[1.2, 1], 2.8])
64+
sys = fractional_to_ordinary([1 - 4*x + x^2 * y, 3*x - x^2 * y], [x, y], [1.3, 0.8], 10^-8, 220; initials=[[1.2, 1], 2.8])
6465
prob = ODEProblem(sys, [], tspan)
6566
sol = solve(prob, radau5(), abstol = 1e-8, reltol = 1e-8)
6667

67-
@test isapprox(1.0097684171, sol(220, idxs=x), atol=1e-3)
68-
@test isapprox(2.1581264031, sol(220, idxs=y), atol=1e-3)
68+
@test isapprox(1.0097684171, sol(220, idxs=x), atol=1e-5)
69+
@test isapprox(2.1581264031, sol(220, idxs=y), atol=1e-5)
70+
71+
#Testing for example 3 of Section 7
72+
@independent_variables t
73+
@variables x_0(t)
74+
D = Differential(t)
75+
tspan = (0., 5000.)
76+
77+
function expect(t)
78+
return sqrt(2) * sin(t + pi/4)
79+
end
80+
81+
sys = linear_fractional_to_ordinary([3, 2.5, 2, 1, .5, 0], [1, 1, 1, 4, 1, 4], 6*cos(t), 10^-5, 5000; initials=[1, 1, -1])
82+
prob = ODEProblem(sys, [], tspan)
83+
sol = solve(prob, radau5(), abstol = 1e-5, reltol = 1e-5)
84+
85+
@test isapprox(expect(5000), sol(5000, idxs=x_0), atol=1e-6)

0 commit comments

Comments
 (0)