如何绘制方程(x ^ 2 + y ^ 2-1)^ 3 = x ^ 2 * y ^ 3?

时间:2018-03-05 02:34:31

标签: r

对于像(x^2+y^2-1)^3=x^2*y^3这样的等式,我使用emdbook,

library(emdbook)
> curve3d((x^2+y^2-1)^3-x^2*y^3,
+         sys3d="contour",level=0,from=c(-10,-10),to=c(10,10),
+         drawlabels=FALSE,axes=FALSE,xlab="",ylab="")  

但错误的情节enter image description here

如何在R中绘制(x^2+y^2-1)^3=x^2*y^3

1 个答案:

答案 0 :(得分:3)

如果从另一侧减去等式的一边,因此解决方案为0,您可以使用outer计算z值的网格,contour可以情节:

x <- seq(-2, 2, by = 0.01)    # high granularity for good resolution
z <- outer(x, x, FUN = function(x, y) x^2*y^3 - (x^2+y^2-1)^3)

# specify level to limit contour lines printed
contour(x, x, z, levels = 0)

或使用tidyverse,

library(tidyverse)

crossing(x = seq(-2, 2, by = 0.01), 
         y = x) %>% 
    mutate(z = x^2*y^3 - (x^2+y^2-1)^3) %>% 
    ggplot(aes(x, y, z = z)) + 
    geom_contour(breaks = 0)