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 then generate the graph based on those.
Here's a related thread, but the solutions there seem to be specific to the 3D case. This question has been more resistant to Googling that I would have expected, so maybe the R language calls implicit formulas something else.
Thanks in advance!
In 2D function graphing mode, it is not possible to graph functions that have an implicit form f(x,y)=g(x,y). For example, the functionx^2+. 5y^2=30 is a implicit function. Only equations having an explicit form y=f(x), where y is unique for each x value can be graphed in this mode.
Plot Multiple Implicit Equations You can plot multiple equations either by passing the inputs as a vector or by using hold on to successively plot on the same figure. If you specify LineSpec and Name-Value arguments, they apply to all lines.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With