简体   繁体   English

如何 R 中的 plot 多变量 function

[英]How to plot multivariate function in R

I am trying to plot the following function:我正在尝试 plot 以下 function: 在此处输入图像描述

This is what I have currently tried:这是我目前尝试过的:

curve(7*x*y/( e^(x^2+y^2)))

But I get the following error:但我收到以下错误:

在此处输入图像描述

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM