12 Factorial

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.

Numeric Vector of 20 to 50 by 5

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

Quadratic Equation Solver

The quadratic equation is ax\(^{2}\) + bx + c. There are severak possible outcomes when solving a quadratic equation.

  1. The equation is actually linear (a = 0) and therefore the value of x is equal to negative c divided by b.
  2. If b\(^{2}\)+4ac is positive, there are two real-numbered roots that aren’t the same.
  3. If b\(^{2}\)+4ac is equal to zero, there’s a double root (and it’s a real number).
  4. b\(^{2}\)+4ac is negative, there aren’t any roots with real numbers in them.
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.")
  }
}