Skip to content

Added Fresnel integrals #398 #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
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))

12 changes: 12 additions & 0 deletions test/fresnel.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@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

z = rand(ComplexF64)
@test fresnel(z) == (fresnelc(z),fresnels(z))
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