title: “Homework_1” output: html_document date: “2022-07-17” R Bridge Week 1 Assignment Please create the following exercises in .rmd format, publish to rpub and submit both the .rmd file and the rpub link. 1. Write a loop that calculates 12-factorial 2. Show how to create a numeric vector that contains the sequence from 20 to 50 by 5. 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.—
Question 1:
num <- 12
fact <- 1
while (num != 1) {
fact <- fact * num
num <- num - 1
print(fact)
}
## [1] 12
## [1] 132
## [1] 1320
## [1] 11880
## [1] 95040
## [1] 665280
## [1] 3991680
## [1] 19958400
## [1] 79833600
## [1] 239500800
## [1] 479001600
Question 2:
numvec <- seq(from=20, to=50, by=5)
print(numvec)
## [1] 20 25 30 35 40 45 50
Question 3:
quadratic <-function(a, b, c) {
d = (b*b - 4*a*c)**0.5
x_1 = (-b + d)/(2*a)
x_2 = (-b - d)/(2*a)
paste("Answer: x=", x_1, "or x=", x_2)
}
quadratic(5,6,1)
## [1] "Answer: x= -0.2 or x= -1"