sici.RdComputes the sine and cosine integrals through approximations.
Si(x)
Ci(x)The sine and cosine integrals are defined as $$Si(x) = \int_0^x \frac{\sin(t)}{t} dt$$ $$Ci(x) = - \int_x^\infty \frac{\cos(t)}{t} dt = \gamma + \log(x) + \int_0^x \frac{\cos(t)-1}{t} dt$$ where \(\gamma\) is the Euler-Mascheroni constant.
Returns a scalar of sine resp. cosine integrals applied to each
element of the scalar/vector. The value Ci(x) is not correct,
it should be Ci(x)+pi*i, only the real part is returned!
The function is not truely vectorized, for vectors the values are
calculated in a for-loop. The accuracy is about 10^-13 and better
in a reasonable range of input values.
Zhang, S., and J. Jin (1996). Computation of Special Functions. Wiley-Interscience.
x <- c(-3:3) * pi
Si(x); Ci(x)
#> [1] -1.674762 -1.418152 -1.851937 0.000000 1.851937 1.418152 1.674762
#> [1] 0.01062020 -0.02256066 0.07366791 -Inf 0.07366791 -0.02256066
#> [7] 0.01062020
if (FALSE) { # \dontrun{
xs <- linspace(0, 10*pi, 200)
ysi <- Si(xs); yci <- Ci(xs)
plot(c(0, 35), c(-1.5, 2.0), type = 'n', xlab = '', ylab = '',
main = "Sine and cosine integral functions")
lines(xs, ysi, col = "darkred", lwd = 2)
lines(xs, yci, col = "darkblue", lwd = 2)
lines(c(0, 10*pi), c(pi/2, pi/2), col = "gray")
lines(xs, cos(xs), col = "gray")
grid()} # }