[英]How to plot multivariate function in R
Your e means exponential function.您的 e 表示指数 function。 In the r, exponential function code is
exp()
.在 r 中,指数 function 代码是
exp()
。 So you can revise this code.所以你可以修改这个代码。
curve(7*x*y/(exp(x^2+y^2)))
One way to plot is using the contour()
function. plot 的一种方法是使用
contour()
function。 Also, as @Sang won kim noted, exp()
is the function for e^(...)
此外,正如@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')
Created on 2019-10-27 by the reprex package (v0.3.0)由reprex package (v0.3.0) 于 2019 年 10 月 27 日创建
You can create a contour plot like this:您可以像这样创建轮廓 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.