[R] plotting a bivariate quadratic curve
Duncan Murdoch
murdoch.duncan at gmail.com
Sat Nov 12 17:47:26 CET 2011
On 11-11-12 5:50 AM, Yackov Lubarsky wrote:
> Hi,
>
> I would like to plot a x,y curve described by the equation :
>
> Ax^2 + Bx + Cy^2 + Dy + E == 0
>
> (A,B,C,D,E are constants)
>
> This sounds like quite the common task but haven't been able to figure
> out how to do this. Could you please help ? I am new to R so probably
> missing something basic.
>
R is not very good at that, but one way to do it is to draw a contour
plot of the bivariate function, with a single contour at level 0. For
example,
A <- B <- C <- D <- 1
E <- -1
x <- y <- seq(-3, 3, len=100)
z <- outer(x, y, function(x, y) A*x^2 + B*x + C*y^2 + D*y + E)
contour(x, y, z, levels=0, drawLabels=FALSE)
Another would be to solve for y as a function of x, and draw both
branches.
Duncan Murdoch
More information about the R-help
mailing list