Skip to content

Commit

Permalink
Add type for step size
Browse files Browse the repository at this point in the history
Signed-off-by: ErikQQY <[email protected]>
  • Loading branch information
ErikQQY committed Feb 19, 2022
1 parent f723d44 commit a9192da
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/Derivative/Caputo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function fracdiff(f::Function, α::Float64, start_point, end_point::AbstractArra
end
=#

function fracdiff(f::Union{Function, Number}, α::Float64, end_point, h, ::Caputo_Piecewise)
function fracdiff(f::Union{Function, Number}, α::Float64, end_point, h::Float64, ::Caputo_Piecewise)
typeof(f) <: Number ? (end_point == 0 ? (return 0) : (return f/sqrt(pi*end_point))) : nothing
end_point == 0 ? (return 0) : nothing
m = floor(Int, α)+1
Expand Down Expand Up @@ -236,7 +236,7 @@ function first_order(f, point, h)
end


function fracdiff(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h, ::Caputo_Piecewise)::Vector
function fracdiff(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::Caputo_Piecewise)::Vector
result = map(x->fracdiff(f, α, x, h, Caputo_Piecewise()), end_point)
return result
end
Expand All @@ -245,7 +245,7 @@ end
#=
Caputo Diethelm algorithm
=#
function fracdiff(f::Union{Function, Number}, α::Float64, end_point::Number, h, ::Caputo_Diethelm)
function fracdiff(f::Union{Function, Number}, α::Float64, end_point::Number, h::Float64, ::Caputo_Diethelm)
#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 @@ -268,7 +268,7 @@ function quadweights(n, N, α)
end
end

function fracdiff(f, α::Float64, end_point::AbstractArray, h, ::Caputo_Diethelm)::Vector
function fracdiff(f, α::Float64, end_point::AbstractArray, h::Float64, ::Caputo_Diethelm)::Vector
result = map(x->fracdiff(f, α, x, h, Caputo_Diethelm()), end_point)
return result
end
Expand Down
10 changes: 5 additions & 5 deletions src/Derivative/GL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ end

#TODO: Use the improved alg!! This algorithm is not accurate
#This algorithm is not so good, still more to do
function fracdiff(f::Union{Function, Number}, α, end_point, h, ::GL_Multiplicative_Additive)::Float64
function fracdiff(f::Union{Function, Number}, α, end_point, h::Float64, ::GL_Multiplicative_Additive)::Float64
typeof(f) <: Number ? (end_point == 0 ? 0 : f/sqrt(pi*end_point)) : nothing
summation = zero(Float64)
n = round(Int, end_point/h)
Expand All @@ -146,7 +146,7 @@ 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::Union{Function, Number}, α::Float64, end_point, h, ::GL_Lagrange_Three_Point_Interp)::Float64
function fracdiff(f::Union{Function, Number}, α::Float64, end_point, h::Float64, ::GL_Lagrange_Three_Point_Interp)::Float64
#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 @@ -170,7 +170,7 @@ function fracdiff(f::Union{Number, Function}, α::Float64, end_point::AbstractAr
end
=#

function fracdiff(f::Union{Number, Function}, α::Float64, end_point, h, ::GL_Finite_Difference)::Float64
function fracdiff(f::Union{Number, Function}, α::Float64, end_point, h::Float64, ::GL_Finite_Difference)::Float64
typeof(f) <: Number ? (end_point == 0 ? 0 : f/sqrt(pi*end_point)) : nothing
n = round(Int, end_point/h)
result = zero(Float64)
Expand Down Expand Up @@ -260,9 +260,9 @@ function getvec(α, n, g)
for k = p+1:n
M = k-1
dA = b/M
temp = (-(g[2:(p+1)] .*collect((1-dA):-dA:(1-p*dA))))' *w[M:-1:(k-p)]./g0 #FIXME: When p is greater than 2 threw DimensionMismatch
temp = (-(g[2:(p+1)] .*collect((1-dA):-dA:(1-p*dA))))' *w[M:-1:(k-p)]/g0
push!(w, temp)
end

return w
end
end
6 changes: 3 additions & 3 deletions src/Derivative/Hadamard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct Hadamard_Trap <: Hadamard end
#=
Hadamard Left Rectangular computing algorithms
=#
function fracdiff(f, α, x₀, x, h, ::Hadamard_LRect)
function fracdiff(f, α, x₀, x, h::Float64, ::Hadamard_LRect)
typeof(f) <: Number ? (x == 0 ? (return 0) : (return f/sqrt(pi*x))) : nothing
x == 0 ? (return 0) : nothing
N = round(Int, (x-x₀)/h)
Expand All @@ -96,7 +96,7 @@ end
#=
Hadamard Right Rectangular computing algorithm
=#
function fracdiff(f, α, x₀, x, h, ::Hadamard_RRect)
function fracdiff(f, α, x₀, x, h::Float64, ::Hadamard_RRect)
typeof(f) <: Number ? (x == 0 ? 0 : f/sqrt(pi*x)) : nothing
N = round(Int, (x-x₀)/h)
result = zero(Float64)
Expand All @@ -120,7 +120,7 @@ end
#=
Hadamard trapezoidal computing algorithm
=#
function fracdiff(f, α, x₀, x, h, ::Hadamard_Trap)
function fracdiff(f, α, x₀, x, h::Float64, ::Hadamard_Trap)
typeof(f) <: Number ? (x == 0 ? 0 : f/sqrt(pi*x)) : nothing
N = round(Int, (x-x₀)/h)

Expand Down
12 changes: 6 additions & 6 deletions src/Derivative/RL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct RL_D <: RLDiff end
################################################################


function fracdiff(f::Union{Number, Function}, α, end_point, h, ::RLDiff_Approx)
function fracdiff(f::Union{Number, Function}, α, end_point, h::Float64, ::RLDiff_Approx)
#checks(f, α, 0, 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 @@ -117,7 +117,7 @@ function fracdiff(f::Union{Number, Function}, α, end_point, h, ::RLDiff_Approx)
return result
end

function fracdiff(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h, ::RLDiff_Approx)::Vector
function fracdiff(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RLDiff_Approx)::Vector
result = map(x->fracdiff(f, α, x, h, RLDiff_Approx()), end_point)
return result
end
Expand Down Expand Up @@ -173,7 +173,7 @@ Page 57
Linear Spline Interpolation
=#
function fracdiff(f::Union{Number, Function}, α, x, h, ::RL_Linear_Spline_Interp)
function fracdiff(f::Union{Number, Function}, α, x, h::Float64, ::RL_Linear_Spline_Interp)
typeof(f) <: Number ? (x == 0 ? (return 0) : (return f/sqrt(pi*x))) : nothing
x == 0 ? (return 0) : nothing
N = round(Int, x/h)
Expand Down Expand Up @@ -210,12 +210,12 @@ function c̄ⱼₖ(j, k, α)
end
end

function fracdiff(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h, ::RL_Linear_Spline_Interp)::Vector
function fracdiff(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RL_Linear_Spline_Interp)::Vector
result = map(x->fracdiff(f, α, x, h, RL_Linear_Spline_Interp()), end_point)
return result
end

function fracdiff(f::Union{Number, Function}, α, start_point, end_point, h, ::RL_G1)
function fracdiff(f::Union{Number, Function}, α, start_point, end_point, h::Float64, ::RL_G1)
typeof(f) <: Number ? (end_point == 0 ? (return 0) : (return f/sqrt(pi*end_point))) : nothing
end_point == 0 ? (return 0) : nothing

Expand All @@ -229,7 +229,7 @@ function fracdiff(f::Union{Number, Function}, α, start_point, end_point, h, ::R
return h^(-α)/gamma(-α)*result
end

function fracdiff(f::Union{Number, Function}, α, point, h, ::RL_D)
function fracdiff(f::Union{Number, Function}, α, point, h::Float64, ::RL_D)
typeof(f) <: Number ? (point == 0 ? (return 0) : (return f/sqrt(pi*point))) : nothing
point == 0 ? (return 0) : nothing

Expand Down
5 changes: 4 additions & 1 deletion src/Derivative/Riesz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ julia> fracdiff(x->x, 0.5, 1, 0.01, Riesz_Symmetric())
struct Riesz_Symmetric <: Riesz end




################################################################
### Type definition done ###
################################################################
Expand All @@ -36,4 +38,5 @@ function RieszMatrix(α, N, h)
result = 1/2*(caputo+caputo')
result = h^(-α)*result
return result
end
end

28 changes: 14 additions & 14 deletions src/Integral/RL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function checks(f, α, start_point, end_point)
end
end

function fracint(f::Union{Function, Number}, α, start_point, end_point::Real, h, ::RL_Direct)
function fracint(f::Union{Function, Number}, α, start_point, end_point::Real, h::Float64, ::RL_Direct)
#checks(f, α, start_point, end_point)
typeof(f) <: Number ? (end_point == 0 ? (return 0) : (return 2*f*sqrt(end_point/pi))) : nothing
end_point == 0 ? (return 0) : nothing
Expand Down Expand Up @@ -294,7 +294,7 @@ end
=#


function fracint(f::Union{Function, Number}, α::Float64, end_point, h, ::RL_Piecewise)::Float64
function fracint(f::Union{Function, Number}, α::Float64, end_point, h::Float64, ::RL_Piecewise)::Float64
#checks(f, α, 0, end_point)
typeof(f) <: Number ? (end_point == 0 ? (return 0) : (return 2*f*sqrt(end_point/pi))) : nothing
end_point == 0 ? (return 0) : nothing
Expand All @@ -320,13 +320,13 @@ function W(i, n, α)
end


function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h, ::RL_Piecewise)::Vector
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RL_Piecewise)::Vector
result = map(x->fracint(f, α, x, h, RL_Piecewise()), end_point)
return result
end


function fracint(f::Union{Function, Number}, α::Float64, end_point, h, ::RLInt_Approx)::Float64
function fracint(f::Union{Function, Number}, α::Float64, end_point, h::Float64, ::RLInt_Approx)::Float64
#checks(f, α, 0, end_point)
typeof(f) <: Number ? (end_point == 0 ? (return 0) : (return 2*f*sqrt(end_point/pi))) : nothing
end_point == 0 ? (return 0) : nothing
Expand All @@ -342,15 +342,15 @@ function fracint(f::Union{Function, Number}, α::Float64, end_point, h, ::RLInt_
return result1
end

function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h, ::RLInt_Approx)::Vector
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RLInt_Approx)::Vector
result = map(x->fracint(f, α, x, h, RLInt_Approx()), end_point)
return result
end




function fracint(f::Union{Function, Number}, α::Float64, end_point::Number, h, ::RL_LinearInterp)::Float64
function fracint(f::Union{Function, Number}, α::Float64, end_point::Number, h::Float64, ::RL_LinearInterp)::Float64
typeof(f) <: Number ? (end_point == 0 ? (return 0) : (return 2*f*sqrt(end_point/pi))) : nothing
end_point == 0 ? (return 0) : nothing

Expand All @@ -366,7 +366,7 @@ function fracint(f::Union{Function, Number}, α::Float64, end_point::Number, h,
return result1
end

function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h, ::RL_LinearInterp)::Vector
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RL_LinearInterp)::Vector
result = map(x->fracint(f, α, x, h, RL_LinearInterp()), end_point)
return result
end
Expand Down Expand Up @@ -404,7 +404,7 @@ end
#=
RLInt_Simpson Algorithm
=#
function fracint(f, α, point, h, ::RLInt_Simpson)
function fracint(f, α, point, h::Float64, ::RLInt_Simpson)
typeof(f) <: Number ? (point == 0 ? (return 0) : (return 2*f*sqrt(point/pi))) : nothing
point == 0 ? (return 0) : nothing

Expand Down Expand Up @@ -436,15 +436,15 @@ function ĉₖₙ(k, n, α)
return ((α+2)*((n+1-k)^(1+α)+(n-k)^(1+α))-2*((n+1-k)^(2+α)-(n-k)^(2+α)))
end

function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h, ::RLInt_Simpson)::Vector
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RLInt_Simpson)::Vector
result = map(x->fracint(f, α, x, h, RLInt_Simpson()), end_point)
return result
end

#=
RLInt_Trapezoidal Algorithm
=#
function fracint(f::Union{Function, Number}, α, point, h, ::RLInt_Trapezoidal)
function fracint(f::Union{Function, Number}, α, point, h::Float64, ::RLInt_Trapezoidal)
typeof(f) <: Number ? (point == 0 ? (return 0) : (return 2*f*sqrt(point/pi))) : nothing
point == 0 ? (return 0) : nothing

Expand All @@ -469,7 +469,7 @@ function aₖₙ(k, n, α)
end


function fracint(f::Union{Number, Function}, α, point, h, ::RLInt_Rectangular)
function fracint(f::Union{Number, Function}, α, point, h::Float64, ::RLInt_Rectangular)
typeof(f) <: Number ? (point == 0 ? (return 0) : (return 2*f*sqrt(point/pi))) : nothing
point == 0 ? (return 0) : nothing

Expand All @@ -487,15 +487,15 @@ function bₖ(k, α)
return (k+1)^α-k^α
end

function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h, ::RLInt_Rectangular)::Vector
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RLInt_Rectangular)::Vector
result = map(x->fracint(f, α, x, h, RLInt_Rectangular()), end_point)
return result
end

#=
RLInt_Cubic_Spline_Interp Algorithm, when h is 0.01 behave best
=#
function fracint(f, α, point, h, ::RLInt_Cubic_Spline_Interp)
function fracint(f, α, point, h::Float64, ::RLInt_Cubic_Spline_Interp)
typeof(f) <: Number ? (point == 0 ? (return 0) : (return 2*f*sqrt(point/pi))) : nothing
point == 0 ? (return 0) : nothing

Expand Down Expand Up @@ -528,7 +528,7 @@ function êⱼₙ(j, n, α)
end
end

function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h, ::RLInt_Cubic_Spline_Interp)::Vector
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RLInt_Cubic_Spline_Interp)::Vector
result = map(x->fracint(f, α, x, h, RLInt_Cubic_Spline_Interp()), end_point)
return result
end

0 comments on commit a9192da

Please sign in to comment.