From 733fb6b4396bac894f3f174a19f20ad0631bbe26 Mon Sep 17 00:00:00 2001 From: Tom McGrath Date: Sun, 9 Feb 2025 15:06:04 -0600 Subject: [PATCH] Implement sin, cos --- src/GaussianRandomVariables.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/GaussianRandomVariables.jl b/src/GaussianRandomVariables.jl index ae24ef7..9cc875e 100644 --- a/src/GaussianRandomVariables.jl +++ b/src/GaussianRandomVariables.jl @@ -227,4 +227,20 @@ function Base.sqrt(a::GVar{<:AbstractFloat}) return GVar(meanvar(sqrt, x -> 1/(2*sqrt(x)), x -> -1/(4 * sqrt(x^3)), a.center, a.σ)...) end +# For the following trigonometric functions, the resulting distributions are not normal, +# but they will still be represented as such +function Base.sin(a::GVar{<:AbstractFloat}) + return GVar( + sin(a.center) * exp(-0.5 * a.σ^2), + 0.5 - 0.5*cos(2*a.center)*exp(-2 * a.σ^2) - (sin(a.center)^2) * exp(-a.σ^2) + ) +end + +function Base.cos(a::GVar{<:AbstractFloat}) + return GVar( + cos(a.center) * exp(-0.5 * a.σ^2), + 0.5 + 0.5 * cos(2*a.center)*exp(-2 * a.σ^2) - (cos(a.center)^2) * exp(-a.σ^2) + ) +end + end # module