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
The roots (solutions) to the quadratic equation ax2 +bx+c = 0 is given by the well-known...
The roots (solutions) to the quadratic equation ax2 +bx+c = 0 is given by the well-known formula x = 2a −b ± √b −4ac 2 Write a python program that takes the three coefficients a, b, and c as input, computes and displays the solutions according to the aforementioned formula. Note the ± in the numerator means there are two answers. But this will not apply if a is zero, so that condition must be checked separately; design your program...
Python programming Write a program that prompts the user to input the three coefficients a, b,...
Python programming Write a program that prompts the user to input the three coefficients a, b, and c of a quadratic equationax2+bx+c= 0.The program should display the solutions of this equation, in the following manner: 1. If the equation has one solution, display ONE SOLUTION:, followed by the solution, displayed with4 digits printed out after the decimal place. 2. If the equation has two real solutions, display TWO REAL SOLUTIONS:, followed by the two solutions, each displayed with4 digits printed...
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...
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...
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...