Elipse, centro(h,k), a: radio mayor, b: radio menor h: ultimos de cedula 5 k: tercer de cedula 3
a.e <- function(a,b){
if(!is.numeric(a) | !is.numeric(b)) 'Terminos no numericos'
else if(a==0 | b==0) 'Terminos deben ser diferentes de 0'
else if(b>a) cat('\n','a debe ser mayor que b (a>b)','\n',
'a: Semi-eje mayor, b: Semi-eje menor')
else{
require(plotrix)
op = par(mfrow = c(2,2))
h = 5; k = 3
A = pi*a*b
e <<- sqrt(a^2-b^2)/a
plot(0, xlim = c(h-a,h+a), ylim = c(k-b,k+b), type = 'n',
main=paste0('Metodo draw.ellipse()\n',
'Excentricidad: ',round(e,2),'\n',
'Area: ',round(A,2)),
xlab = 'X', ylab = 'Y')
draw.ellipse(h,k,a,b)
points(h,k,col='blue',pch=16)
text(h,k*0.9,paste0('centro(',h,',',k,')'))
x = seq(h-a,h+a,length.out = 100)
y = seq(k-b,k+b,length.out = 100)
z = outer(x,y,function(x,y){(((x-h)^2)/a^2)+(((y-k)^2)/b^2)-1})
contour(x,y,z,levels=0,
main=paste0('Metodo contour()\n',
'Excentricidad: ',round(e,2),'\n',
'Area: ',round(A,2)),
xlab = 'X', ylab = 'Y')
points(h,k,col='blue',pch=16)
text(h,k*0.9,paste0('centro(',h,',',k,')'))
y1 = c(-sqrt(b^2*(1-((x-h)^2)/a^2))+k,
sqrt(b^2*(1-((x-h)^2)/a^2))+k)
plot(y1~c(x,x[length(x):1]), type='l',
main =paste0('Metodo plot()\n',
'Excentricidad: ',round(e,2),'\n',
'Area: ',round(A,2)),
xlab = 'X', ylab = 'Y')
points(h,k,col='blue',pch=16)
text(h,k*0.9,paste0('centro(',h,',',k,')'))
###
b.g = seq(a,0,length.out = 100)
b.g = b.g[-length(b.g)]
e.g = sqrt(a^2-b.g^2)/a
plot(e.g~b.g, type='l',
xlab = 'b', ylab='e',
main = paste0('Excentricidad vs b\n',
'siempre b <= a'))
par(op)
}
}
a.e(1,1)
## Loading required package: plotrix
a.e(2,1)
a.e(5,1)
a.e(1,3)
##
## a debe ser mayor que b (a>b)
## a: Semi-eje mayor, b: Semi-eje menor
a.e('a',1)
## [1] "Terminos no numericos"
a.e(0,1)
## [1] "Terminos deben ser diferentes de 0"