File size: 2,365 Bytes
21ad80b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | # Load required libraries
library(plotly)
lp_norm_surface_fun <- function(p) {
func <- function(x, y) {
return((abs(x)^p + abs(y)^p)^(1 / p))
}
return(func)
}
# Generate a grid of points in 2D space
x <- seq(-10, 10, length.out = 100)
y <- seq(-10, 10, length.out = 100)
# Plotting the surface for p = 1/4
numerator <- 1
demonator <- 4
p1 <- plot_ly(
x = x,
y = y,
z = outer(x, y, lp_norm_surface_fun(numerator / demonator)),
type = "surface"
) |>
layout(
title = paste0("L_", numerator, "/", demonator, " Norm Surface"),
scene = list(
xaxis = list(title = "x"),
yaxis = list(title = "y"),
zaxis = list(title = "z", range = c(0, 200))
)
)
# Plotting the surface for p = 1/3
numerator <- 1
demonator <- 3
p2 <- plot_ly(
x = x,
y = y,
z = outer(x, y, lp_norm_surface_fun(numerator / demonator)),
type = "surface"
) |>
layout(
title = paste0("L_", numerator, "/", demonator, " Norm Surface"),
scene = list(
xaxis = list(title = "x"),
yaxis = list(title = "y"),
zaxis = list(title = "z", range = c(0, 95))
)
)
# Plotting the surface for p = 2
numerator <- 2
demonator <- 1
p3 <- plot_ly(
x = x,
y = y,
z = outer(x, y, lp_norm_surface_fun(numerator / demonator)),
type = "surface"
) |>
layout(
title = paste0("L_", numerator, " Norm Surface"),
scene = list(
xaxis = list(title = "x"),
yaxis = list(title = "y"),
zaxis = list(title = "z")
)
)
# Plotting the surface for p = 3
numerator <- 3
demonator <- 1
p4 <- plot_ly(
x = x,
y = y,
z = outer(x, y, lp_norm_surface_fun(numerator / demonator)),
type = "surface"
) |>
layout(
title = paste0("L_", numerator, " Norm Surface"),
scene = list(
xaxis = list(title = "x"),
yaxis = list(title = "y"),
zaxis = list(title = "z")
)
)
# Plotting the surface for p = 0.7 used by HQQ
numerator <- 7
demonator <- 10
p5 <- plot_ly(
x = x,
y = y,
z = outer(x, y, lp_norm_surface_fun(numerator / demonator)),
type = "surface"
) |>
layout(
# title = paste0("L_", numerator, "/", demonator, " Norm Surface"),
scene = list(
xaxis = list(title = "x"),
yaxis = list(title = "y"),
zaxis = list(title = "z", range = c(0, 35))
)
) |>
hide_colorbar()
save_image(p5, "lpnorm-visual.pdf", weight = 1000, height = 600)
|