Skip to content

Commit 842276b

Browse files
committed
Spiced up readme
1 parent 67d2656 commit 842276b

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,47 @@
44
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://kiranshila.github.io/FresnelIntegrals.jl/dev)
55
[![Build Status](https://travis-ci.com/kiranshila/FresnelIntegrals.jl.svg?branch=master)](https://travis-ci.com/kiranshila/FresnelIntegrals.jl)
66
[![Codecov](https://codecov.io/gh/kiranshila/FresnelIntegrals.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/kiranshila/FresnelIntegrals.jl)
7+
8+
A quick Julia library for calculating Fresnel Integrals using the error function from [SpecialFunctions.jl](https://github.com/JuliaMath/SpecialFunctions.jl).
9+
10+
```julia
11+
using FresnelIntegrals
12+
using Plots
13+
14+
z = -30:0.001:30
15+
plot(x->real(fresnelc(x)), x->real(fresnels(x)),z,legend=false,xlabel="C(x)",ylabel="S(x)",title="Euler Spiral")
16+
```
17+
![Spiral](Spiral.png)
18+
19+
As expected, this is much faster than the numeric integral solution
20+
21+
```julia
22+
using QuadGK
23+
using FresnelIntegrals
24+
25+
julia> @benchmark fresnelc(1.8)
26+
BenchmarkTools.Trial:
27+
memory estimate: 0 bytes
28+
allocs estimate: 0
29+
--------------
30+
minimum time: 410.815 ns (0.00% GC)
31+
median time: 412.035 ns (0.00% GC)
32+
mean time: 426.088 ns (0.00% GC)
33+
maximum time: 1.017 μs (0.00% GC)
34+
--------------
35+
samples: 10000
36+
evals/sample: 200
37+
38+
julia> @benchmark quadgk(z->cos*z^2/2),0,1.8)
39+
BenchmarkTools.Trial:
40+
memory estimate: 1.00 KiB
41+
allocs estimate: 42
42+
--------------
43+
minimum time: 2.181 μs (0.00% GC)
44+
median time: 2.250 μs (0.00% GC)
45+
mean time: 3.357 μs (31.54% GC)
46+
maximum time: 7.919 ms (99.89% GC)
47+
--------------
48+
samples: 10000
49+
50+
```

Spiral.png

32.3 KB
Loading

src/FresnelIntegrals.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module FresnelIntegrals
22
using SpecialFunctions
33
export fresnelc
44
export fresnels
5+
export fresnel
56

67
"""
78
fresnelc(z)
@@ -15,4 +16,10 @@ Calculates the Fresnel sine integral for the number z
1516
"""
1617
fresnels(z::Number) = 0.25*(1+1im)*(-1im*erf(0.5*(1-1im)*z*√(π)) + erf(0.5*(1+1im)*z*√(π)))
1718

19+
"""
20+
fresnel(z)
21+
Calculates the cosine and sine fresnel integrals
22+
"""
23+
fresnel(z::Number) = (fresnelc(z),fresnels(z))
24+
1825
end # module

test/runtests.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
using FresnelIntegrals
22
using Test
3+
using QuadGK
34

45
@testset "FresnelIntegrals.jl" begin
5-
# Write your own tests here.
6+
# Generate random complex number
7+
z = randn(ComplexF64)
8+
# Test by comparing to numeric solution
9+
@test fresnelc(z) quadgk(t->cos*t^2/2),0,z)[1]
10+
@test fresnels(z) quadgk(t->sin*t^2/2),0,z)[1]
11+
# Test just for code coverage 😄
12+
@test (fresnelc(z),fresnels(z)) == fresnel(z)
613
end

0 commit comments

Comments
 (0)