factorialResult <- 1
for(i in 2:12){
factorialResult <- factorialResult*i
}
print(factorialResult)
## [1] 479001600
numVec <- seq(20,50,5)
print(numVec)
## [1] 20 25 30 35 40 45 50
plot(numVec)
\[ax^2 + bx + c = 0\]
\[x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\] Discriminant: \[\sqrt{b^2 - 4ac}\]
fct <- function (a, b, c)
{
disc <- (b^2) - (4*a*c)
print(paste("The discriminant is ", disc))
if(disc > 0) {
sol1 <- (-b + sqrt(disc)) / (2*a)
sol1 <- (-b - sqrt(disc)) / (2*a)
print(paste("The two real solutions are:", sol1, "and", sol1, "."))
}
else if(disc == 0) {
sol2 <- (-b) / (2*a)
print(paste("There is only one solution:", sol2))
}
else
print(paste("There are no solutions"))
}
#Two Solutions
fct (40,-31,-52)
## [1] "The discriminant is 9281"
## [1] "The two real solutions are: -0.816724335412634 and -0.816724335412634 ."
#No Solutions
fct (-1,3,-6)
## [1] "The discriminant is -15"
## [1] "There are no solutions"