Without using the factorial function, the best way to do get the factorial of a number is with a recursive loop. We already know that a factorial takes a list of numbers from 1 to n, where n is the number we are doing a factorial of, and multiplies those numbers together. It is depicted as n!. So 3! would be 3 x 2 x 1, which is 6.
Thus, the factorial of 12 would be…
## [1] 479001600
I attempted to use in-line code for the output, but it put it into scientific notation.
To make a numeric vector with certain intervals, you’ll want to use the “seq” function. The three variables for it are from (the starting number), to (the final number), and by (how much each number in the sequence increases or decreases on its way to the “to” number).
seq(from = 20, to = 50, by = 5)
## [1] 20 25 30 35 40 45 50
The quadratic equation is ax\(^{2}\) + bx + c. There are severak possible outcomes when solving a quadratic equation.
factorial <- function(a,b,c){
if (a == 0){
return(-c/b)
} else if ( (b^2-4*a*c) > 0 ) {
x1 = ( -b + sqrt( (b^2-4*a*c) ) )/( 2*a )
x2 = ( -b - sqrt( (b^2-4*a*c) ) )/( 2*a )
return( c(x1, x2) )
} else if ( (b^2-4*a*c) == 0){
return(-b/(2*a))
} else {
return("No roots with real numbers.")
}
}