[英]How to plot multivariate function in R
您的 e 表示指數 function。 在 r 中,指數 function 代碼是exp()
。 所以你可以修改這個代碼。
curve(7*x*y/(exp(x^2+y^2)))
plot 的一種方法是使用contour()
function。 此外,正如@Sang won kim 所說, exp()
是e^(...)
的 function
x <- seq(from = 0.01, to = 2.1, by = 0.01)
y <- x
multi_var_fx <- function (x, y) {
7 * x * y / (exp(x^2 + y^2))
}
z <- outer(x, y, multi_var_fx)
contour(x, y, z, xlab = 'x', ylab = 'y')
由reprex package (v0.3.0) 於 2019 年 10 月 27 日創建
您可以像這樣創建輪廓 plot :
library(tidyverse)
tibble(x = seq(0, 10, 0.1), # define the drawing grid
y = seq(0, 10, 0.1)
) %>%
cross_df() %>% # create all possible combinations of x and y
mutate(z = 7*x*y/(exp(x^2+y^2)) ) %>% # add your function
ggplot(aes(x = x, y = y, z = z)) + # create the plot
geom_contour()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.