# Copia quanto segue e incollalo in R.
source("http://macosa.dima.unige.it/r.R")
f1 <- function(x,y) (x-2*y)^2+3*y-4
f2 <- function(x,y) (x-y)*(x+2*y)+3*y-4
f3 <- function(x,y) x^2/2+y^2+3*y-4
PIANO(-5,5, -5,5)
curva(f1,"blue"); curva(f2,"red"); curva(f3,"brown")
#
# Alternativa (senza caricare il file precedente):
f1 <- function(x,y) (x-2*y)^2+3*y-4
f2 <- function(x,y) (x-y)*(x+2*y)+3*y-4
f3 <- function(x,y) x^2/2+y^2+3*y-4
x1 <- -4; x2 <- 4; y1 <- -4; y2 <- 4
x <- seq(x1,x2,len=1000); y <- seq(y1,y2,len=1000)
z <- outer(x,y,f1); contour(x,y,z,levels=0,drawlabels=FALSE, lwd=3,col="blue",asp=1)
abline(h=axTicks(2), v=axTicks(1),lty=3,col="blue")
abline(h=0, v=0,lty=2,col="blue")
z <- outer(x,y,f2); contour(x,y,z,levels=0,lwd=3,col="red",add=TRUE,drawlabels=FALSE)
z <- outer(x,y,f3); contour(x,y,z,levels=0,lwd=3,col="violet",add=TRUE,drawlabels=FALSE)
# Per approfondimenti vedi qui.

  

# Ecco come potrebbero essere tracciate diversamente e studiate pił a fondo le
# coniche precedenti
conic() #Use Conic(w) where w is c(a,b,c,d,e,f) for a*x^2+b*x*y+c*y^2+d*x+e*y+f = 0 #C1 and, as appropriate, xC,yC, xV,yV, xF,yF, xF1,yF1, xF2,yF2, FV are stored #Use fraction(xC),..,fraction(yF2) if you want to try to find fractional forms BF=2.6; HF=2.6 # (x-2*y)^2+3*y-4 = x^2-4*x*y+4*y^2+3*y-4 co1=c(1,-4,4,0,3,-4); Conic(co1) #C1=function(x,y) 1 * x^2 + -4 * x*y + 4 * y^2 + 0 * x + 3 * y + -4 #parabola xV = 3.026667 yV = 1.213333 dir.ax.symm = -2 -1 #F 2.966667 1.183333 In C2(x,y) there is the directrix # fuoco e vertice sono vicini; scelgo una scala con cui staccarli PLANE(2.5,3.5, 0.5,1.5) CUR(C1,"blue"); Point(xF,yF,"magenta"); Point(xV,yV,"red") CUR(C2,"seagreen") # # (x-y)*(x+2*y)+3*y-4 = x^2+x*y-2*y^2+3*y-4 co2=c(1,1,-2,0,3,-4); Conic(co2) #C1=function(x,y) 1 * x^2 + 1 * x*y + -2 * y^2 + 0 * x + 3 * y + -4 #hyperbola xC = -0.3333333 yC = 0.6666667 #dir.trasv.ax 3.081139 0.5 dir.coniug.ax -0.5 3.081139 #V1 1.310946 0.9334964 V2 -1.977612 0.3998369 #F1 1.693533 0.9955817 F2 -2.360199 0.3377516 eccentr 1.232678 #In C2 there is the curve formed by the 2 asymptotes PLANE(-5,5, -5,5); CURV(C1,"red") Point(xV1,yV1,"blue"); Point(xV2,yV2,"blue") Point(xF1,yF1,"magenta"); Point(xF2,yF2,"magenta") CUR(C2,"seagreen") # co3=c(1/2,0,1,0,3,-4); Conic(co3) #C1=function(x,y) 0.5 * x^2 + 0 * x*y + 1 * y^2 + 0 * x + 3 * y + -4 #ellipse xC = 0 yC = -1.5 #dir.major ax: 0 ° dir.minor ax: 270 ° #semi-major axis 3.535534 semi-minor axis 2.5 #F1 2.5 -1.5 F2 -2.5 -1.5 eccentr 0.7071068 #Then you have the length of the string that draws the Ellipse with #StringE(xF1,yF1, xF2,yF2) [which is = major axis = distance V1-V2] #and the couple of hor/vert dist. from F1 (F2) to V1 (V2) with FV PLANE(-4,4, -5,3); CURV(C1,"brown") Point(xF1,yF1,"red"); Point(xF2,yF2,"red"); Point(xC,yC,"brown") Point(xF2-FV[1],yF2+FV[2],"black"); Point(xF1+FV[1],yF1-FV[2],"black") line(xF1,yF1,0,2.5+yC,"seagreen"); line(xF2,yF2,0,2.5+yC,"seagreen")