Skip to content

Commit

Permalink
Make GL and Hadamard type stable
Browse files Browse the repository at this point in the history
Signed-off-by: ErikQQY <[email protected]>
  • Loading branch information
ErikQQY committed Mar 23, 2024
1 parent e4f1c5f commit bf1d09e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
30 changes: 17 additions & 13 deletions src/Derivative/GL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ The **p** here is the grade of precision.
!!! note
The value interval passing in the function should be a array!
"""
struct GLHighPrecision <: GL end
struct GLHighPrecision <: GL
p::Int
end

GLHighPrecision(; p::Int=2) = GLHighPrecision(p)


################################################################
Expand All @@ -109,10 +113,10 @@ struct GLHighPrecision <: GL end
Grunwald Letnikov direct method
=#
function fracdiff(f::FunctionAndNumber,
α::Float64,
α::T,
start_point::Real,
end_point::Real,
::GLDirect)::Float64
::GLDirect) where {T <: Real}
#checks(f, α, start_point, end_point)
typeof(f) <: Number ? (end_point == 0 ? (return 0) : (return f/sqrt(pi*end_point))) : nothing
end_point == 0 ? (return 0) : nothing
Expand All @@ -126,7 +130,7 @@ fracdiff(f::FunctionAndNumber, α::Float64, end_point, ::GLDirect) = fracdiff(f:

#TODO: Use the improved alg!! This algorithm is not accurate
#This algorithm is not so good, still more to do
function fracdiff(f::FunctionAndNumber, α, end_point, h::Float64, ::GLMultiplicativeAdditive)::Float64
function fracdiff(f::FunctionAndNumber, α, end_point, h::Real, ::GLMultiplicativeAdditive)
typeof(f) <: Number ? (end_point == 0 ? 0 : f/sqrt(pi*end_point)) : nothing
summation = zero(Float64)
n = round(Int, end_point/h)
Expand All @@ -151,10 +155,10 @@ end
#TODO: This algorithm is same with the above one, not accurate!!!
#This algorithm is not so good, still more to do
function fracdiff(f::FunctionAndNumber,
α::Float64,
α::Real,
end_point::Real,
h::Float64,
::GLLagrangeThreePointInterp)::Float64
h::Real,
::GLLagrangeThreePointInterp)
#checks(f, α, 0, end_point)
typeof(f) <: Number ? (end_point == 0 ? 0 : f/sqrt(pi*end_point)) : nothing
n = round(Int, end_point/h)
Expand All @@ -178,10 +182,10 @@ end
=#

function fracdiff(f::FunctionAndNumber,
α::Float64,
α::Real,
end_point::Real,
h::Float64,
::GLFiniteDifference)::Float64
h::Real,
::GLFiniteDifference)
typeof(f) <: Number ? (end_point == 0 ? 0 : f/sqrt(pi*end_point)) : nothing
n = round(Int, end_point/h)
result = zero(Float64)
Expand All @@ -207,10 +211,10 @@ end


function fracdiff(f::Union{Function, Number, Vector},
α::Float64,
α::T,
t,
p::Int64,
::GLHighPrecision)
alg::GLHighPrecision) where {T <: Real}
p = @unpack p = alg
if isa(f, Function)
y=f.(t)
elseif isa(f, Vector)
Expand Down
16 changes: 8 additions & 8 deletions src/Derivative/Hadamard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ struct HadamardTrap <: HadamardDiff end
Hadamard Left Rectangular computing algorithms
=#
function fracdiff(f::FunctionAndNumber,
α::Float64,
α::Real,
x₀,
x::Real,
h::Float64,
h::Real,
::HadamardLRect)
typeof(f) <: Number ? (x == 0 ? (return 0) : (return f/sqrt(pi*x))) : nothing
x == 0 ? (return 0) : nothing
Expand All @@ -90,7 +90,7 @@ function fracdiff(f::FunctionAndNumber,

return 1/gamma(1-α)*result
end
function LRectCoeff(i::Int64, n::Int64, h::Float64, α::Float64, x₀)
function LRectCoeff(i::P, n::P, h::T, α::T, x₀) where {P <: Integer, T <: Real}
if 0 i n-2
return ((log((x₀+n*h)/(x₀+i*h)))^(-α) - (log((x₀+n*h)/(x₀+(i+1)*h)))^(-α))
elseif i == n-1
Expand All @@ -102,10 +102,10 @@ end
Hadamard Right Rectangular computing algorithm
=#
function fracdiff(f::FunctionAndNumber,
α::Float64,
α::Real,
x₀::Real,
x::Real,
h::Float64,
h::Real,
::HadamardRRect)
typeof(f) <: Number ? (x == 0 ? 0 : f/sqrt(pi*x)) : nothing
N = round(Int, (x-x₀)/h)
Expand All @@ -117,7 +117,7 @@ function fracdiff(f::FunctionAndNumber,

return 1/gamma(1-α)*result
end
function RRectCoeff(i::Int64, n::Int64, h::Float64, α::Float64, x₀::Real)
function RRectCoeff(i::P, n::P, h::Real, α::Real, x₀::Real) where {P <: Integer}
if i == 0
return 1/2*LRectCoeff(i, n, h, α, x₀)
elseif 1 i n-1
Expand All @@ -131,10 +131,10 @@ end
Hadamard trapezoidal computing algorithm
=#
function fracdiff(f::FunctionAndNumber,
α::Float64,
α::Real,
x₀::Real,
x::Real,
h::Float64,
h::Real,
::HadamardTrap)
typeof(f) <: Number ? (x == 0 ? 0 : f/sqrt(pi*x)) : nothing
N = round(Int, (x-x₀)/h)
Expand Down

0 comments on commit bf1d09e

Please sign in to comment.