Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A quadratic equation is mainly a parabola which goes through an extremum that could be a minimum if a>0 or a maximum if a <0...just

A quadratic equation is mainly a parabola which goes through an extremum that could be a minimum if a>0 or a maximum if a<0...just to convince yourself, you can plot the function using your preferred software or just click here https://www.wolframalpha.com/input/?i=plot+2*x%5E2%2B3*x%2B1 the program is then computing the x = x0 position of the extremum, and return the value of the function at the extremum f(x0) (as you could see in the plot of the function for our particular example).

An extremum of a function is obtained when f(x) = 0 (derivative), and basic math should give youx = b/(2a) that we call x0 here.

What you need to implement:

  1. Just compute the extremum x0 and return its value

  2. Use the function evaluate quad equation written in Task-2 to return the value of f(x0)

  3. The code is displaying a summary sentence that provides the values of x0 and f(x0) and must also specifies if it is a minimum (like in this example) or a maximum (if you try your code with a value of a<0).

Task-4-[20pts]

Let us continue with the execution.

Welcome to Quadratic Solver for f(x)=ax**2+bx+c 
Enter value for a: 2 Enter value for b: 3 Enter value for c: 1 
Equation is: f(x)=2.0x**2+3.0x+1.0 
Press Enter to continue... Enter value for x: 3.0 f(3.0)= 28.0 
Press Enter to continue... f(x) has a minimum at x0=-0.75 with value f(x0)=-0.125 
Press Enter to continue... Solving for f(x)=0 Discriminant is 1.0 Two real solutions: -0.5 and -1.0 
Thanks for using Quadratic solver!, come back soon 

After this execution, the program must end by skipping a line and displayingThanks for using Quadratic solver!, come back soon.

3

By steps, the program must: (1) simply display what this execution is doing, mainly solving for f(x) = 0, (2) compute and display the discriminant (value of d = b2 4ac), (3) return the values of the solutions. Ifd > 0 like in this case, the program will return two real solutions

x1=b+ d, and x2=b d

If d = 0 the program should return only one real solution x0 = b/(2a) (which happened to be the extremum already calculated in Task-3). If you choose the inputs a=1, b=2, c=1, the output (at this stage of the execution) should look like:

2a 2a

Press Enter to continue... Solving for f(x)=0 Discriminant is 0.0 One real solution: -1.0 
Thanks for using Quadratic solver!, come back soon 

If d < 0 there is no real solutions, using the inputs a=1, b=1, c=2 (for example), the program should then return (at this stage of the execution):

Press Enter to continue... Solving for f(x)=0 Discriminant is -7.0 No real solutions 
Thanks for using Quadratic solver!, come back soon 

What you need to implement:

  1. a new function called compute discriminant that will take a,b,c as inputs and return the value of d.

  2. you will need to use some conditional statements to differentiate between the cases d = 0.0, d > 0.0 and d < 0.0.

  3. To compute the solutions you need to use the square root function Python does not provide a built-in sqrt function, we will import it from the Math module. At the root (top) of your file add the following instruction import math you will then be able to call the square root function of x (for example) as follows: math.sqrt(x)

Task-5- [5pts]

If you made it that far it means that your program is executing correctly. Now, we aim at handling some special cases (corner cases). If you decide to enter as input a=1, b=1.0, c=2.5 (for example), most likely your output for the equation would currently look like:

However, when the coefficients a and b are equal to 1.0, then there is no need to include them in the expression. What we would like to get is:

x known as sqrt(x). Since

Equation is: f(x)=1.0x**2+1.0x+2.5 

4

Equation is: f(x)=x**2+x+2.5 

You need to change the code (function my quad equation) appropriately to make this happen.Task-6- [5pts]

If you decide to enter as input a=-3.5, b=-2, c=-3 (for example), most likely your output for the equation would currently look like:

The (+-) is kind of ugly. We need to see the following instead:

You need to change the code (function my quad equation) appropriately to make this happen. Hint: we note that x = |x| if x is negative, and x = |x| if x is positive. The absolute value function is a Python built-in function that can be called using abs(x).

In the cases where a=-1 and b=-1, we should also get (here c=3.0):

Task-7-[5pts]

Once the program tells you that one or two solutions are obtained, you could display just after the factorized form of f(x). For example if x1and x2 are solutions, the factorized form is f(x) = a (x x1)(x x2), if only x0 is solution then it is f(x) = a (x x0)2. Example of execution using 2,1,-1 for a,b,c gives:

Equation is: f(x)=-3.5x**2+-2.0x+-3.0 
Equation is: f(x)=-3.5x**2-2.0x-3.0 
Equation is: f(x)=-x**2-x+3.0 
Press Enter to continue... Solving for f(x)=0 Discriminant is 9.0 Two real solutions: 0.5 and -1.0 Factorize form is: f(x)=2.0*(x-0.5)(x+1.0) 
Thanks for using Quadratic solver!, come back soon 

Using 1,2,1 for a,b,c we should get:

5

Press Enter to continue... Solving for f(x)=0 Discriminant is 0.0 One real solution: -1.0 Factorize form is: f(x)=(x+1.0)**2 
Thanks for using Quadratic solver!, come back soon 

You could define a new function factorize form to accomplish this. As you can see, the factorize form can manage the correct sign nicely in the expression.

Task-8-[5pts]

If d < 0 there is no real solutions but there are two solutions in the complex plane. The formula to compute these solutions is the same than the real formula above but now we need to evaluate the square root of a negative number. This can easily be done using the regular square root function since, if x is negative thenj|x| is its square root (j stands for imaginary number). You can modify your program to display the complex solutions as follows for the case of a=1, b=1, c=2

Press Enter to continue... Solving for f(x)=0 Discriminant is -7.0 No real solutions 
Complex solutions are (-0.5+1.3228756555322954j) and (-0.5-1.3228756555322954j) Thanks for using Quadratic solver!, come back soon 

Task-9-[Bonus 5pts]

In your program you may use a conditional statement for comparing the value of d with 0.0. It is always difficult to compare float numbers. For example by using a=2.5, b=3.2, c=1.024, it is easy to show thatd = b2 4ac should be equal to 0. However, with Python you will most likely obtain something liked = 1.7763568394002505e 15 that makes it difficult to use a conditional statement while comparing with the value 0.0. Find a way to solve this problem. Note that no TAs help will be provided for bonus question.

I have done tasks 1-4 I need the program for the rest

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Decisions Based On Data Analytics For Business Excellence

Authors: Bastian Weber

1st Edition

9358681683, 978-9358681680

Students also viewed these Databases questions

Question

Describe a persuasive message.

Answered: 1 week ago

Question

Identify and use the five steps for conducting research.

Answered: 1 week ago

Question

List the goals of a persuasive message.

Answered: 1 week ago