#SPS R-Track HomeWork 1 ## Done by Tage Singh ** Question 1 **

factorial = 1
for(i in 1:12) {
factorial = factorial * i
}
print(paste("The factorial of 12 is",factorial))
## [1] "The factorial of 12 is 479001600"

** Question 2 **

#(" For this question we will use a sequence generator, this allows us to set the numeric change factor of the sequence - as show below")

numVec <- seq(20,50, by=5)
print("The results of the sequence from 20 to 50 in increments of 5 is : ")
## [1] "The results of the sequence from 20 to 50 in increments of 5 is : "
print(numVec)
## [1] 20 25 30 35 40 45 50

** Question 3 **

A quadratic equation is in the form a(x)^2 + bx + c

The user inputs are variables a,b,c

There are 2 possible solution for x in this type of equation

The first solution is x = ((-b) +/- (((b2)-(4ac)).5))/(2*a)

The solution

# An "R" function to solve a quadratic
solve.quadratic <- function(a,b,c){

# discriminant - used to simplify the solution computation
d = b^2 - 4*a*c

#solutions for real
if (d >= 0){
sol1 = (-b + sqrt(d))/(2*a)
sol2 = (-b - sqrt(d))/(2*a)

}

#for complex roots
if (d < 0){
  sol1 = (-b + sqrt(Mod(d))*1i)/(2*a) # Using the MOD function for absolute value of d
  sol2 = (-b - sqrt(Mod(d))*1i)/(2*a) #1i for imaginary part
}
#printing solutions
print(" The values of X that satisfies the quadratic are :")

print(sol1)

print(sol2)

}

#calling the function
solve.quadratic(1,-2,-35)
## [1] " The values of X that satisfies the quadratic are :"
## [1] 7
## [1] -5