Construction curves defined by equations in R

Is there a way in R to construct two-dimensional curves given by equations? For example, how can I build the hyperbola given by the equation x ^ 2 - 3 * y ^ 2 + 2 * x * y - 20 = 0?

+8
r graphics
source share
3 answers

You can use contour to build two hyperbole branches.

 f <- function(x,y) x^2 - 3*y^2 + 2*x*y - 20 x <- y <- seq(-10,10,length=100) z <- outer(x,y,f) contour( x=x, y=x, z=z, levels=0, las=1, drawlabels=FALSE, lwd=3 ) 

enter image description here

+15
source share

For write only - ggplot version

 library(ggplot2) library(dplyr) f <- function(x,y) x^2 - 3*y^2 + 2*x*y - 20 seq(-10,+10,length=100) %>% expand.grid(x=.,y=.) %>% mutate(z=f(x,y)) %>% ggplot + aes(x=x,y=y,z=z) + stat_contour(breaks=0) 

enter image description here

+1
source share

perhaps the solution can transform the equation into a formula and use the curve () to plot it.

curve(sqrt(4/9*x^2-20/3) + x/3,-20,20)

0
source share

All Articles