Skip to content

Commit

Permalink
Cover tests for GL
Browse files Browse the repository at this point in the history
Signed-off-by: ErikQQY <2283984853@qq.com>
  • Loading branch information
ErikQQY committed Feb 4, 2022
1 parent 7a030f0 commit 8696c43
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/Derivative/GL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ function fracdiff(f::Union{Function, Number}, α, end_point, h, ::GL_Multiplicat

return result
end

#=
function fracdiff(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h, ::GL_Multiplicative_Additive)::Vector
ResultArray = Float64[]
for (_, value) in enumerate(end_point)
append!(ResultArray, fracdiff(f, α, value, h, GL_Multiplicative_Additive()))
end
return ResultArray
end

=#

#TODO: This algorithm is same with the above one, not accurate!!!
#This algorithm is not so good, still more to do
Expand All @@ -163,15 +163,15 @@ function fracdiff(f::Union{Function, Number}, α::Float64, end_point, h, ::GL_La

return result
end

#=
function fracdiff(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h, ::GL_Lagrange_Three_Point_Interp)::Vector
ResultArray = Float64[]
for (_, value) in enumerate(end_point)
append!(ResultArray, fracdiff(f, α, value, h, GL_Lagrange_Three_Point_Interp()))
end
return ResultArray
end

=#

function fracdiff(f::Union{Number, Function}, α::Float64, end_point, h, ::GL_Finite_Difference)::Float64
typeof(f) <: Number ? (end_point == 0 ? 0 : f/sqrt(pi*end_point)) : nothing
Expand All @@ -185,7 +185,7 @@ function fracdiff(f::Union{Number, Function}, α::Float64, end_point, h, ::GL_Fi
result1 = result*h^(-α)*gamma+1)
return result1
end

#=
function fracdiff(f::Union{Function, Number}, α::AbstractArray, end_point, h, ::GL_Finite_Difference)::Vector
ResultArray = Float64[]
Expand All @@ -194,7 +194,7 @@ function fracdiff(f::Union{Function, Number}, α::AbstractArray, end_point, h, :
end
return ResultArray
end

=#



Expand Down
2 changes: 1 addition & 1 deletion src/FractionalCalculus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export Caputo, GL, RLDiff, Hadamard
export Caputo_Direct, Caputo_Piecewise, Caputo_Diethelm, Caputo_High_Precision

# Grünwald Letnikov sense fractional derivative
export GL_Direct, GL_Multiplicative_Additive, GL_Lagrange_Three_Point_Interp, GL_High_Precision
export GL_Direct, GL_Multiplicative_Additive, GL_Lagrange_Three_Point_Interp, GL_Finite_Difference, GL_High_Precision

# Riemann Liouville sense fractional derivative
export RLDiff_Approx, RLDiff_Matrix, RL_Linear_Spline_Interp, RL_G1, RL_D
Expand Down
12 changes: 12 additions & 0 deletions test/Derivative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ end
@test isapprox(fracdiff(x->x, 0.5, collect(0:0.01:1), 2, GL_High_Precision())[end], 2/sqrt(pi); atol = 1e-4)
end

@testset "Test GL_Multiplicative_Additive()" begin
@test isapprox(fracdiff(x->x, 0.5, 1, 0.009, GL_Multiplicative_Additive()), 2/sqrt(pi); atol=1e-2)
end

@testset "Test GL_Lagrange_Three_Point_Interp" begin
@test isapprox(fracdiff(x->x, 0.5, 1, 0.009, GL_Lagrange_Three_Point_Interp()), 2/sqrt(pi); atol=1e-2)
end

@testset "Test GL_Finite_Difference" begin
@test isapprox(fracdiff(x->x, 0.5, 1, 0.009, GL_Finite_Difference()), 2/sqrt(pi); atol=1e-2)
end

@testset "Test Grunwald Letnikov Lagrange_Three_Point_Interp" begin
@test isapprox(fracdiff(x->x, 0.5, 1, 0.01, GL_Lagrange_Three_Point_Interp()), 2/sqrt(pi); atol=1e-4)
end
Expand Down

0 comments on commit 8696c43

Please sign in to comment.