Question

Write an R function that takes three input values which would be three coefficients, solves quadratic...

Write an R function that takes three input values which would be three coefficients,

solves quadratic equations, and prints both roots.

If the roots are the same, print the root only once. # If there are no real roots, print the message "There are no real roots."

For information of the quadratic equations, here is the Wiki page link

https://en.wikipedia.org/wiki/Quadratic_equation

Your code below

Then call the function you've just created and input the coefficients for
the equations 3x^2 +5x + 9, x^2 -3x + 2, and x^2 +2x +1.
Your code below

Homework Answers

Answer #1

I will give the code and the screenshot of the output of your example given,

result <- function(a,b,c)
{
    if(discriminant(a,b,c) > 0)
    { 
        # first case D>0
        x_1 = (-b+sqrt(discriminant(a,b,c)))/(2*a)
        x_2 = (-b-sqrt(discriminant(a,b,c)))/(2*a)
        result = c(x_1,x_2)
    }
    else if(discriminant(a,b,c) == 0)
    {
        # second case D=0
        x = -b/(2*a)
    }
    else 
    {
        # third case D<0
        "There are no real roots."
    } 
}
discriminant<-function(a,b,c)
{
    # Calculate the discriminant
    b^2-4*a*c
}
print("First equation : ")
print(result(3,5,9))
print("Second equation : ")
print(result(1,-3,2))
print("Third equation : ")
print(result(1,2,1))

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT