|
1 | 1 | module FresnelIntegrals
|
2 | 2 | using SpecialFunctions
|
3 |
| -export fresnelc |
4 |
| -export fresnels |
5 |
| -export fresnel |
| 3 | +using IrrationalConstants: sqrtπ |
| 4 | +export fresnelc, fresnels, fresnel |
6 | 5 |
|
7 | 6 | """
|
8 |
| - fresnelc(z) |
9 |
| -Calculates the Fresnel cosine integral for the number z for |
10 |
| - ``C(z) = \\int_{0}^{z} \\cos{\\left(\\frac{\\pi t^2}{2}\\right)}dt`` |
| 7 | + fresnelc(z::Number) |
| 8 | +
|
| 9 | +Calculate the normalized Fresnel cosine integral |
| 10 | +```math |
| 11 | +C(z) = \\int_{0}^{z} \\cos{\\left(\\frac{\\pi t^2}{2}\\right)} \\, \\mathrm{d}t |
| 12 | +``` |
| 13 | +for the number ``z``. |
11 | 14 | """
|
12 |
| -fresnelc(z::Number) = 0.25*(1-1im)*(1im*erf(0.5*(1-1im)*z*√(π)) + erf(0.5*(1+1im)*z*√(π))) |
| 15 | +function fresnelc(z::Number) |
| 16 | + x = (z * sqrtπ) / 2 |
| 17 | + re_x, im_x = reim(x) |
| 18 | + a = (re_x + im_x) + (im_x - re_x) * im |
| 19 | + b = (re_x - im_x) + (im_x + re_x) * im |
| 20 | + re_erf_a, im_erf_a = reim(erf(a)) |
| 21 | + re_erf_b, im_erf_b = reim(erf(b)) |
| 22 | + re_y = (re_erf_a - im_erf_a + re_erf_b + im_erf_b) / 4 |
| 23 | + im_y = (im_erf_a + re_erf_a - re_erf_b + im_erf_b) / 4 |
| 24 | + y = re_y + im_y * im |
| 25 | + return y |
| 26 | +end |
| 27 | +function fresnelc(z::Real) |
| 28 | + x = (z * sqrtπ) / 2 |
| 29 | + a = x + x * im |
| 30 | + re_erf_a, im_erf_a = reim(erf(a)) |
| 31 | + y = (re_erf_a + im_erf_a) / 2 |
| 32 | + return y |
| 33 | +end |
13 | 34 |
|
14 | 35 | """
|
15 |
| - fresnels(z) |
16 |
| -Calculates the Fresnel sine integral for the number z for |
17 |
| - ``S(z) = \\int_{0}^{z} \\sin{\\left(\\frac{\\pi t^2}{2}\\right)}dt`` |
| 36 | + fresnels(z::Number) |
| 37 | +
|
| 38 | +Calculate the normalized Fresnel sine integral |
| 39 | +```math |
| 40 | +S(z) = \\int_{0}^{z} \\sin{\\left(\\frac{\\pi t^2}{2}\\right)} \\, \\mathrm{d}t |
| 41 | +``` |
| 42 | +for the number ``z``. |
18 | 43 | """
|
19 |
| -fresnels(z::Number) = 0.25*(1+1im)*(-1im*erf(0.5*(1-1im)*z*√(π)) + erf(0.5*(1+1im)*z*√(π))) |
| 44 | +function fresnels(z::Number) |
| 45 | + x = (z * sqrtπ) / 2 |
| 46 | + re_x, im_x = reim(x) |
| 47 | + a = (re_x + im_x) + (im_x - re_x) * im |
| 48 | + b = (re_x - im_x) + (im_x + re_x) * im |
| 49 | + re_erf_a, im_erf_a = reim(erf(a)) |
| 50 | + re_erf_b, im_erf_b = reim(erf(b)) |
| 51 | + re_y = (re_erf_a + im_erf_a + re_erf_b - im_erf_b) / 4 |
| 52 | + im_y = (im_erf_a - re_erf_a + re_erf_b + im_erf_b) / 4 |
| 53 | + y = re_y + im_y * im |
| 54 | + return y |
| 55 | +end |
| 56 | +function fresnels(z::Real) |
| 57 | + x = (z * sqrtπ) / 2 |
| 58 | + a = x + x * im |
| 59 | + re_erf_a, im_erf_a = reim(erf(a)) |
| 60 | + y = (re_erf_a - im_erf_a) / 2 |
| 61 | + return y |
| 62 | +end |
20 | 63 |
|
21 | 64 | """
|
22 |
| - fresnel(z) |
23 |
| -Calculates the cosine and sine fresnel integrals |
| 65 | + fresnel(z::Number) |
| 66 | +
|
| 67 | +Calculate the normalized cosine and sine fresnel integrals. |
| 68 | +
|
| 69 | +See also [`fresnels`](@ref), [`fresnelc`](@ref). |
24 | 70 | """
|
25 |
| -fresnel(z::Number) = (fresnelc(z),fresnels(z)) |
| 71 | +function fresnel(z::Number) |
| 72 | + x = (z * sqrtπ) / 2 |
| 73 | + re_x, im_x = reim(x) |
| 74 | + a = (re_x + im_x) + (im_x - re_x) * im |
| 75 | + b = (re_x - im_x) + (im_x + re_x) * im |
| 76 | + re_erf_a, im_erf_a = reim(erf(a)) |
| 77 | + re_erf_b, im_erf_b = reim(erf(b)) |
| 78 | + re_y_sin = (re_erf_a + im_erf_a + re_erf_b - im_erf_b) / 4 |
| 79 | + im_y_sin = (im_erf_a - re_erf_a + re_erf_b + im_erf_b) / 4 |
| 80 | + re_y_cos = (re_erf_a - im_erf_a + re_erf_b + im_erf_b) / 4 |
| 81 | + im_y_cos = (im_erf_a + re_erf_a - re_erf_b + im_erf_b) / 4 |
| 82 | + y_sin = re_y_sin + im_y_sin * im |
| 83 | + y_cos = re_y_cos + im_y_cos * im |
| 84 | + return (y_cos, y_sin) |
| 85 | +end |
| 86 | +function fresnel(z::Real) |
| 87 | + x = (z * sqrtπ) / 2 |
| 88 | + a = x + x * im |
| 89 | + re_erf_a, im_erf_a = reim(erf(a)) |
| 90 | + y_sin = (re_erf_a - im_erf_a) / 2 |
| 91 | + y_cos = (re_erf_a + im_erf_a) / 2 |
| 92 | + return (y_cos, y_sin) |
| 93 | +end |
| 94 | + |
| 95 | + |
26 | 96 |
|
27 | 97 | end # module
|
0 commit comments