—Week1
factorial<-function (x){ y<- 1 for(i in 1:x) {
y<-y*((1:x)[i]) print(y) } }
factorial(12)
numvect <-seq(from =20, to =50, by =5 ) numvect
quadFunction <- function(a, b, c) { numSqrt <- b^2 - 4ac if(numSqrt > 0) { x1 <- (-b+sqrt(b^2 - 4ac))/(2a) x2 <- (-b-sqrt(b^2 - 4ac))/(2a) x <- c(x1, x2) x } else if (numSqrt == 0) { x <- -b/(2*a) x } else {“No results when the number under square root less than 0.”} }
numeric <- as.character(“a”,“b”,“c”) a<- (1) b<- (2) c<- (1) quadFunction (1,2,1) # [1] -1
numeric <- as.character(“a”,“b”,“c”) a<- (1) b<- (6) c<- (5) quadFunction (1,6,5) ## [1] -1 -5
numeric <- as.character(“a”,“b”,“c”) a<- (1) b<- (1) c<- (1) quadFunction(1,1,1) ## [1] “No results when the number under square root less than 0.