I am trying to plot a besselJ() function of order 0 (nu = 0) for x = 0 to x = 20 in R (working in RStudio). Here is my current code:
plot (
x = NULL,
xlim = c(0, 20),
ylim = c(-0.4, 1),
main = "Plot of Bessel functions",
xlab = "x",
ylab = "J_nu(x)"
)
# grid
grid(
col = "gray60",
lwd = 1.5
)
# horizontal reference line
segments(
x0 = 0,
y0 = 0,
x1 = 20,
y1 = 0,
lty = "solid",
lwd = 2,
col = "gray50"
)
# vertical reference line
segments(
x0 = 0,
y0 = -0.4,
x1 = 0,
y1 = 1,
lty = "solid",
lwd = 2,
col = "gray50"
)
curve(
besselJ(0:20, 1),
lty = "solid",
lwd = 3,
col = "salmon2",
add = TRUE
)
This results in the following error:
Error in curve(besselJ(0:20, 1), lty = "solid", lwd = 3, col = "salmon2", : 'expr' must be a function, or a call or an expression containing 'x'
My working thought is that besselJ() returns a value y for a particular value x, which is why curve() is not treating besselJ as a 'function' Anyone else have other ideas?