diff --git a/src/SpecialFunctions.jl b/src/SpecialFunctions.jl index c4fe6120..aea55de4 100644 --- a/src/SpecialFunctions.jl +++ b/src/SpecialFunctions.jl @@ -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") diff --git a/src/fresnel.jl b/src/fresnel.jl new file mode 100644 index 00000000..09c6731e --- /dev/null +++ b/src/fresnel.jl @@ -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)) + diff --git a/test/fresnel.jl b/test/fresnel.jl new file mode 100644 index 00000000..ec94a9b6 --- /dev/null +++ b/test/fresnel.jl @@ -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 \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index f4a30360..1bcac8de 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -32,7 +32,8 @@ tests = [ "gamma", "sincosint", "other_tests", - "chainrules" + "chainrules", + "fresnel" ] const testdir = dirname(@__FILE__)