## Representation of Gegenbauer polynomials (Chebyshev polynomials for p = 2)
th <- seq(0, pi, l = 500)
k <- 0:3
old_par <- par(mfrow = c(2, 2))
for (p in 2:5) {
matplot(th, t(Gegen_polyn(theta = th, k = k, p = p)), lty = 1,
type = "l", main = substitute(p == d, list(d = p)),
axes = FALSE, xlab = expression(theta), ylab = "")
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()
mtext(text = expression({C[k]^{p/2 - 1}}(cos(theta))), side = 2,
line = 2, cex = 0.75)
legend("bottomleft", legend = paste("k =", k), lwd = 2, col = seq_along(k))
}
par(old_par)
## Coefficients and series in p = 2
# Function in [0, pi] to be projected in Chebyshev polynomials
psi <- function(th) -sin(th / 2)
# Coefficients
p <- 2
k <- 0:4
(coefs <- Gegen_coefs(k = k, p = p, psi = psi))
# Series
plot(th, psi(th), type = "l", axes = FALSE, xlab = expression(theta),
ylab = "", ylim = c(-1.25, 0))
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()
col <- viridisLite::viridis(length(coefs))
for (i in seq_along(coefs)) {
lines(th, Gegen_series(theta = th, coefs = coefs[1:(i + 1)], k = 0:i,
p = p), col = col[i])
}
lines(th, psi(th), lwd = 2)
## Coefficients and series in p = 3
# Function in [0, pi] to be projected in Gegenbauer polynomials
psi <- function(th) tan(th / 3)
# Coefficients
p <- 3
k <- 0:10
(coefs <- Gegen_coefs(k = k, p = p, psi = psi))
# Series
plot(th, psi(th), type = "l", axes = FALSE, xlab = expression(theta),
ylab = "", ylim = c(0, 2))
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()
col <- viridisLite::viridis(length(coefs))
for (i in seq_along(coefs)) {
lines(th, Gegen_series(theta = th, coefs = coefs[1:(i + 1)], k = 0:i,
p = p), col = col[i])
}
lines(th, psi(th), lwd = 2)
# \donttest{
## Surface representation
# Surface in [0, pi]^2 to be projected in Gegenbauer polynomials
p <- 3
psi <- function(th_1, th_2) A_theta_x(theta = th_1, x = cos(th_2),
p = p, as_matrix = TRUE)
# Coefficients
k <- 0:20
m <- 0:10
coefs <- Gegen_coefs_2d(k = k, m = m, p = p, psi = psi)
# Series
th <- seq(0, pi, l = 100)
col <- viridisLite::viridis(20)
old_par <- par(mfrow = c(2, 2))
image(th, th, A_theta_x(theta = th, x = cos(th), p = p), axes = FALSE,
col = col, zlim = c(0, 1), xlab = expression(theta[1]),
ylab = expression(theta[2]), main = "Original")
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, at = c(0, pi / 4, pi / 2, 3 * pi / 4, pi),
labels = expression(0, pi / 4, pi / 2, 3 * pi / 4, pi))
box()
for(K in c(5, 10, 20)) {
A <- Gegen_series_2d(theta_1 = th, theta_2 = th,
coefs = coefs[1:(K + 1), ], k = 0:K, m = m, p = p)
image(th, th, A, axes = FALSE, col = col, zlim = c(0, 1),
xlab = expression(theta[1]), ylab = expression(theta[2]),
main = paste(K, "x", m[length(m)], "coefficients"))
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, at = c(0, pi / 4, pi / 2, 3 * pi / 4, pi),
labels = expression(0, pi / 4, pi / 2, 3 * pi / 4, pi))
box()
}
par(old_par)
# }
Run the code above in your browser using DataLab