# Plot A_x(theta) for several dimensions and x's
A_lines <- function(x, th = seq(0, pi, l = 200)) {
plot(th, A_theta_x(theta = th, x = x, p = 2), type = "l",
col = 1, ylim = c(0, 1.25), main = paste("x =", x),
ylab = expression(A[x](theta)),
xlab = expression(theta), axes = FALSE)
axis(1, at = c(0, pi / 4, pi / 2, 3 * pi / 4, pi),
labels = expression(0, pi / 4, pi / 2, 3 * pi / 4, pi))
axis(2); box()
abline(h = c(0, 1), lty = 2)
lines(th, A_theta_x(theta = th, x = x, p = 3), col = 2)
lines(th, A_theta_x(theta = th, x = x, p = 4), col = 3)
lines(th, A_theta_x(theta = th, x = x, p = 5), col = 4)
legend("top", lwd = 2, legend = paste("p =", 2:5),
col = 1:4, cex = 0.75, horiz = TRUE)
}
old_par <- par(mfrow = c(2, 3))
A_lines(x = -0.75)
A_lines(x = -0.25)
A_lines(x = 0)
A_lines(x = 0.25)
A_lines(x = 0.5)
A_lines(x = 0.75)
par(old_par)
# As surface of (theta, x) for several dimensions
A_surf <- function(p, x = seq(-1, 1, l = 201), th = seq(0, pi, l = 201)) {
col <- c("white", viridisLite::viridis(20))
breaks <- c(-1, seq(1e-15, 1, l = 21))
A <- A_theta_x(theta = th, x = x, p = p)
image(th, x, A, main = paste("p =", p), col = col, breaks = breaks,
xlab = expression(theta), axes = FALSE)
axis(1, at = c(0, pi / 4, pi / 2, 3 * pi / 4, pi),
labels = expression(0, pi / 4, pi / 2, 3 * pi / 4, pi))
axis(2); box()
contour(th, x, A, levels = breaks, add = TRUE)
}
old_par <- par(mfrow = c(2, 2))
A_surf(p = 2)
A_surf(p = 3)
A_surf(p = 4)
A_surf(p = 5)
par(old_par)
# No matrix return
th <- seq(0, pi, l = 5)
x <- seq(-1, 1, l = 5)
diag(A_theta_x(theta = th, x = x, p = 2))
A_theta_x(theta = th, x = x, p = 2, as_matrix = FALSE)
Run the code above in your browser using DataLab