We want to solve the quadratic equation ax^2 + bx + c = 0. Thus write a function
ID: 3144166 • Letter: W
Question
We want to solve the quadratic equation ax^2 + bx + c = 0. Thus write a function in R which takes in (a, b, c) and gives you the roots. In class when we did this we avoided imaginary roots. But this time if you have imaginary roots you have to print them out as well. Upload your R-code as problem1.R. Problem 2 Given a number n, write a function f(n) to find the sum of all numbers between 1 and n which are divisible by 3 or 5 (or both). For example f(20) = 3 + 5 + 6 + 9 + 10 + 12 + 15 + 18 + 20 = 98 Upload your R-code as problem2.R. Problem 3 Given a number x > 1, write a function f(x) which returns a whole number n such that, 2^n-1Explanation / Answer
Please post all 3 problems separately.
R-code
root <- function (a,b,c)
{
D = b^2-4*a*c
if(D>=0)
{root1 <- (-b+(D)^(0.5))/(2*a); root2 <- (-b-(D)^(0.5))/(2*a)}
if(D<0)
{root1 <- (-b+i(-D)^(0.5))/(2*a); root2 <- (-b-i(-D)^(0.5))/(2*a)}
print(root1)
print(root2)
}