En este documento se presenta cómo resolver ecuaciones de segundo grado y sistemas de ecuaciones de dos incógnitas utilizando el lenguaje R.
La forma general es:
\[ax^2 + bx + c = 0\]
Resolver:
\[2x^2 - 4x - 6 = 0\]
a <- 2
b <- -4
c <- -6
discriminante <- b^2 - 4*a*c
x1 <- (-b + sqrt(discriminante)) / (2*a)
x2 <- (-b - sqrt(discriminante)) / (2*a)
cat("Las soluciones son:\n")
## Las soluciones son:
cat("x1 =", x1, "\n")
## x1 = 3
cat("x2 =", x2)
## x2 = -1
\[2x^2−4x−6=0\]
# Coeficientes
a <- 2
b <- -4
c <- -6
# Función cuadrática
f <- function(x) {
a*x^2 + b*x + c
}
# Valores de x
x <- seq(-3, 4, by=0.1)
# Soluciones
discriminante <- b^2 - 4*a*c
x1 <- (-b + sqrt(discriminante)) / (2*a)
x2 <- (-b - sqrt(discriminante)) / (2*a)
# Gráfica
plot(x, f(x), type="l", lwd=2,
main="Gráfica de 2x^2 - 4x - 6",
xlab="x", ylab="f(x)")
abline(h=0, col="red", lty=2)
# Marcar raíces
points(c(x1, x2), c(0,0), pch=19)
text(x1, 0, labels=paste("x1 =", round(x1,2)), pos=3)
text(x2, 0, labels=paste("x2 =", round(x2,2)), pos=3)
\[x + y = 5\] \[2x - y = 1\]
A <- matrix(c(1,1,2,-1), nrow=2, byrow=TRUE)
B <- matrix(c(5,1), nrow=2)
solucion <- solve(A,B)
cat("x =", solucion[1], "\n")
## x = 2
cat("y =", solucion[2])
## y = 3
\[x + y = 5\] \[2x - y = 1\]
\[y = 5 - x\] \[y = 2x - 1\]
# Valores de x
x <- seq(-1, 6, by=0.1)
# Ecuaciones
y1 <- 5 - x
y2 <- 2*x - 1
# Gráfica
plot(x, y1, type="l", lwd=2,
main="Sistema de ecuaciones",
xlab="x", ylab="y",
ylim=c(-2,7))
lines(x, y2, lwd=2, lty=2)
# Punto de intersección
sol_x <- 2
sol_y <- 3
points(sol_x, sol_y, pch=19)
text(sol_x, sol_y, labels="(2,3)", pos=3)
legend("topright",
legend=c("x + y = 5", "2x - y = 1"),
lty=c(1,2),
lwd=2)