R Bridge Week 1 Assignment

###1. Write a loop that calculates 12-factorial

factorial(12)
## [1] 479001600
x <- 1
output <- 1
for (x in 1:12) {
    output <- x * output
}
output
## [1] 479001600

see ‘for loop’ pg125

###2. Show how to create a numeric vector that contains the sequence from 20 to 50 by 5.

seq (from=20, to =50, by = 5)
## [1] 20 25 30 35 40 45 50

Answer to number two above; pg 228.

###3. Create the function “quadratic” that takes a trio of input numbers a, b, and c and solve the quadratic equation. The function should print as output the two solutions.

QuadraticFunction <- function(a,b,c) {
  discriminant   <- (b^2) - (4*a*c)
  Add  <- (-b + sqrt (discriminant)) / (2*a)
  sub <- (-b - sqrt (discriminant)) / (2*a)
  return(c(Add,sub))
  
}
QuadraticFunction(a=3, b=10,c=5)
## [1] -0.6125741 -2.7207592

Answer to number three above; b^2 - 4ac= discriminant and is more than zero meaning two roots or two x-intercepts. Remember its case sensitive.

-Marjete