Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting implicit function

Tags:

graph

r

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!

like image 575
half-pass Avatar asked Oct 03 '12 05:10

half-pass


People also ask

Can you graph implicit functions?

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.

How do you plot multiple implicit functions in Matlab?

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.


1 Answers

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

like image 196
IRTFM Avatar answered Oct 02 '22 20:10

IRTFM