Skip to content

Commit

Permalink
added Fresnel integrals
Browse files Browse the repository at this point in the history
Added fresnel integrals from this repo : https://github.com/kiranshila/FresnelIntegrals.jl. As suggested in JuliaMath#398
  • Loading branch information
curio-sitas committed Jul 11, 2022
1 parent 36c547b commit c3474da
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/SpecialFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ export
expintx,
sinint,
cosint,
lbinomial
lbinomial,
fresnelc,
fresnels,
fresnel

include("bessel.jl")
include("erf.jl")
include("fresnel.jl")
include("ellip.jl")
include("expint.jl")
include("sincosint.jl")
Expand Down
25 changes: 25 additions & 0 deletions src/fresnel.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


# Code ported from https://github.com/kiranshila/FresnelIntegrals.jl


"""
fresnelc(z)
Calculates the Fresnel cosine integral for the number z for
``C(z) = \\int_{0}^{z} \\cos{\\left(\\frac{\\pi t^2}{2}\\right)}dt``
"""
fresnelc(z::Number) = 0.25*(1-1im)*(1im*erf(0.5*(1-1im)*z*√(π)) + erf(0.5*(1+1im)*z*√(π)))

"""
fresnels(z)
Calculates the Fresnel sine integral for the number z for
``S(z) = \\int_{0}^{z} \\sin{\\left(\\frac{\\pi t^2}{2}\\right)}dt``
"""
fresnels(z::Number) = 0.25*(1+1im)*(-1im*erf(0.5*(1-1im)*z*√(π)) + erf(0.5*(1+1im)*z*√(π)))

"""
fresnel(z)
Calculates the cosine and sine fresnel integrals
"""
fresnel(z::Number) = (fresnelc(z),fresnels(z))

9 changes: 9 additions & 0 deletions test/fresnel.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@testset "fresnel" begin
# Precise values come from WolframAlpha calculator
# One could add more decimals and more tests if needed

@test fresnels(1.) 0.4382591473903
@test fresnelc(1.) 0.7798934003768
@test fresnels(sqrt(2)) 0.7139722140219
@test fresnelc(sqrt(2)) 0.5288915951112
end
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ tests = [
"gamma",
"sincosint",
"other_tests",
"chainrules"
"chainrules",
"fresnel"
]

const testdir = dirname(@__FILE__)
Expand Down

0 comments on commit c3474da

Please sign in to comment.