Reputation: 163
I am trying to plot the following function:
This is what I have currently tried:
curve(7*x*y/( e^(x^2+y^2)))
But I get the following error:
Upvotes: 0
Views: 2503
Reputation: 999
You can create a contour plot like this:
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()
Upvotes: 1
Reputation: 11255
One way to plot is using the contour()
function. Also, as @Sang won kim noted, exp()
is the function for e^(...)
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)
Upvotes: 1
Reputation: 522
Your e means exponential function. In the r, exponential function code is exp()
. So you can revise this code.
curve(7*x*y/(exp(x^2+y^2)))
Upvotes: 1