Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sici

Sine and Cosine Integral Functions


Description

Computes the sine and cosine integrals through approximations.

Usage

Si(x)
Ci(x)

Arguments

x

Scalar or vector of real numbers.

Details

The sine and cosine integrals are defined as

Si(x) = \int_0^x \frac{\sin(t)}{t} dt

Ci(x) = - \int_x^∞ \frac{\cos(t)}{t} dt = γ + \log(x) + \int_0^x \frac{\cos(t)-1}{t} dt

where γ is the Euler-Mascheroni constant.

Value

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.

References

Zhang, S., and J. Jin (1996). Computation of Special Functions. Wiley-Interscience.

See Also

Examples

x <- c(-3:3) * pi
Si(x); Ci(x)

## Not run: 
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()
## End(Not run)

pracma

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.