Plotting implicit function

前端 未结 1 842
时光说笑
时光说笑 2020-12-10 03:59

I\'m trying to plot the following implicit formula in R:

1 = x^2 + 4*(y^2) + x*y

which should be an ellipse. I\'d like to randomly sample the x values and th

相关标签:
1条回答
  • 2020-12-10 04:41

    Two things you may not understand. When plotting implicit functions with that technique, you need to move all terms to the RHS of the function so that your implicit function becomes:

    0 = -1+ x^2 + 4*(y^2) + x*y
    

    Then using the contour value of zero will make sense:

    x<-seq(-1.1,1.1,length=1000)
    y<-seq(-1,1,length=1000)
    z<-outer(x,y,function(x,y) 4*y^2+x^2+x*y -1 )
    contour(x,y,z,levels=0)
    

    I got a sign wrong on the first version. @mnels' was correct.

    enter image description here

    0 讨论(0)
提交回复
热议问题