-
Notifications
You must be signed in to change notification settings - Fork 103
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
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c3474da
added Fresnel integrals
curio-sitas e103ccf
Added all function test
curio-sitas 906883f
Update src/fresnel.jl
curio-sitas 1308cf3
Update src/fresnel.jl
curio-sitas c950b55
Update src/fresnel.jl
curio-sitas f518b8c
Update src/fresnel.jl
curio-sitas b6f5952
Update src/fresnel.jl
curio-sitas feeb34f
Update src/fresnel.jl
curio-sitas 9723743
Update src/fresnel.jl
curio-sitas 476b012
Update src/fresnel.jl
curio-sitas c558fd9
Update src/fresnel.jl
curio-sitas e520579
Update src/fresnel.jl
curio-sitas b8a7c20
Update src/fresnel.jl
curio-sitas b3b5d4f
Update
curio-sitas 08ed9e9
Update
curio-sitas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Code ported from https://github.com/kiranshila/FresnelIntegrals.jl | ||
|
||
|
||
""" | ||
fresnelcos(z::Number) | ||
|
||
Calculate the normalized Fresnel cosine integral | ||
```math | ||
C(z) = \\int_{0}^{z} \\cos{\\left(\\frac{\\pi t^2}{2}\\right)} \\, \\mathrm{d}t | ||
``` | ||
for the number ``z``. | ||
""" | ||
function fresnelcos(z::Number) | ||
x = (z * sqrtπ) / 2 | ||
re_x, im_x = reim(x) | ||
a = (re_x + im_x) + (im_x - re_x) * im | ||
b = (re_x - im_x) + (im_x + re_x) * im | ||
re_erf_a, im_erf_a = reim(erf(a)) | ||
re_erf_b, im_erf_b = reim(erf(b)) | ||
re_y = (re_erf_a - im_erf_a + re_erf_b + im_erf_b) / 4 | ||
im_y = (im_erf_a + re_erf_a - re_erf_b + im_erf_b) / 4 | ||
y = re_y + im_y * im | ||
return y | ||
end | ||
function fresnelcos(z::Real) | ||
x = (z * sqrtπ) / 2 | ||
a = x + x * im | ||
re_erf_a, im_erf_a = reim(erf(a)) | ||
y = (re_erf_a + im_erf_a) / 2 | ||
return y | ||
end | ||
|
||
""" | ||
fresnelsin(z::Number) | ||
|
||
Calculate the normalized Fresnel sine integral | ||
```math | ||
S(z) = \\int_{0}^{z} \\sin{\\left(\\frac{\\pi t^2}{2}\\right)} \\, \\mathrm{d}t | ||
``` | ||
for the number ``z``. | ||
""" | ||
function fresnelsin(z::Number) | ||
x = (z * sqrtπ) / 2 | ||
re_x, im_x = reim(x) | ||
a = (re_x + im_x) + (im_x - re_x) * im | ||
b = (re_x - im_x) + (im_x + re_x) * im | ||
re_erf_a, im_erf_a = reim(erf(a)) | ||
re_erf_b, im_erf_b = reim(erf(b)) | ||
re_y = (re_erf_a + im_erf_a + re_erf_b - im_erf_b) / 4 | ||
im_y = (im_erf_a - re_erf_a + re_erf_b + im_erf_b) / 4 | ||
y = re_y + im_y * im | ||
return y | ||
end | ||
function fresnelsin(z::Real) | ||
x = (z * sqrtπ) / 2 | ||
a = x + x * im | ||
re_erf_a, im_erf_a = reim(erf(a)) | ||
y = (re_erf_a - im_erf_a) / 2 | ||
return y | ||
end | ||
|
||
curio-sitas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
fresnelsincos(z::Number) | ||
|
||
Calculate the normalized cosine and sine fresnel integrals. | ||
|
||
See also [`fresnelsin`](@ref), [`fresnelcos`](@ref). | ||
""" | ||
function fresnelsincos(z::Number) | ||
x = (z * sqrtπ) / 2 | ||
re_x, im_x = reim(x) | ||
a = (re_x + im_x) + (im_x - re_x) * im | ||
b = (re_x - im_x) + (im_x + re_x) * im | ||
re_erf_a, im_erf_a = reim(erf(a)) | ||
re_erf_b, im_erf_b = reim(erf(b)) | ||
re_y_sin = (re_erf_a + im_erf_a + re_erf_b - im_erf_b) / 4 | ||
im_y_sin = (im_erf_a - re_erf_a + re_erf_b + im_erf_b) / 4 | ||
re_y_cos = (re_erf_a - im_erf_a + re_erf_b + im_erf_b) / 4 | ||
im_y_cos = (im_erf_a + re_erf_a - re_erf_b + im_erf_b) / 4 | ||
y_sin = re_y_sin + im_y_sin * im | ||
y_cos = re_y_cos + im_y_cos * im | ||
return (y_cos, y_sin) | ||
end | ||
function fresnelsincos(z::Real) | ||
x = (z * sqrtπ) / 2 | ||
a = x + x * im | ||
re_erf_a, im_erf_a = reim(erf(a)) | ||
y_sin = (re_erf_a - im_erf_a) / 2 | ||
y_cos = (re_erf_a + im_erf_a) / 2 | ||
return (y_cos, y_sin) | ||
end | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using QuadGK | ||
@testset "fresnel" begin | ||
# Generate random complex number | ||
z = randn(ComplexF64) | ||
# Test by comparing to numeric solution | ||
@test fresnelcos(z) ≈ quadgk(t->cos(π*t^2/2),0,z)[1] | ||
@test fresnelsin(z) ≈ quadgk(t->sin(π*t^2/2),0,z)[1] | ||
# Test just for code coverage 😄 | ||
@test (fresnelcos(z),fresnelsin(z)) == fresnelsincos(z) | ||
|
||
# Generate random real number | ||
z = randn(Float64) | ||
# Test by comparing to numeric solution | ||
@test fresnelcos(z) ≈ quadgk(t->cos(π*t^2/2),0,z)[1] | ||
@test fresnelsin(z) ≈ quadgk(t->sin(π*t^2/2),0,z)[1] | ||
# Test just for code coverage 😄 | ||
@test (fresnelcos(z),fresnelsin(z)) == fresnelsincos(z) | ||
|
||
# Precise values come from WolframAlpha calculator | ||
# One could add more decimals and more tests if needed | ||
|
||
@test fresnelsin(1.) ≈ 0.4382591473903 | ||
@test fresnelcos(1.) ≈ 0.7798934003768 | ||
@test fresnelsin(sqrt(2)*im) ≈ -0.7139722140219*im | ||
@test fresnelcos(sqrt(2)*im) ≈ 0.5288915951112*im | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ checktol(err::Float64) = err ≤ 1e-13 | |
|
||
|
||
tests = [ | ||
"fresnel", | ||
"bessel", | ||
"beta_inc", | ||
"betanc", | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.