# TEXT CODE
# import matplot module
import matplotlib
# import math library
import math
# initialize variable c = 1 to keep track the number of plots
plotted
c = 0
# start main while loop
while True:
# get value of coefficient a
a = float(input("Enter value of coefficient 'a' ( Enter 0 to quit )
: "))
# if a is 0 break
if a == 0: break
# get value of coefficient b
b = float(input("Enter value of coefficient 'b': "))
# get value of coefficient c
c = float(input("Enter value of coefficient 'c': "))
# calculate D (using formula D = b^2 - 4ac)
D = b*b - 4*a*c
if D < 0:
print("\nNo real solutions")
# continue main while loop
continue
if D == 0:
# calculate root x1
x1 = (-b)/(2*a)
print("\none solution: ", x1)
if D > 0:
# calculate root x1
x1 = (-b + math.sqrt(D))/(2*a)
# calculate root x2
x2 = (-b - math.sqrt(D))/(2*a)
print("\ntwo solutions:", x1, " ", x2)
# initialize xs to empty list
xs = []
# initialize ys to empty list
ys = []
# initialize i to -0.5(this is be used in below nested while
loop )
i = -5.0
# nested while loop to generate 100 flaoting points number
while i < 5.0:
# store i into x
x = i
# append x to xs
xs.append(x)
# append value of (ax^2 + bx + c) int ys
ys.append(a*(x**2) + b*x + c)
# get next floating point number (trucate to one decimal
point)
i = float('%.1f'%(i + 0.1))
# plot the function line in "blue" line and "dots" passing third
argument "b." in function plot()
matplotlib.pyplot.plot(xs, ys, "b.")
matplotlib.pyplot.xlabel("x")
matplotlib.pyplot.ylabel("y")
# get the title as figure number( str(c) has been used to convert
int c to string )
title = "figure" + str(c)
# assign the title to plot
matplotlib.pyplot.title( title )
# show the plot
matplotlib.pyplot.show()
# increase value of variable c by 1 (remember c keeps track of plot
number )
c = c + 1
SCREENSHOTS:
code:
output:
DQuestion 19 28 pts Problem 2. Quadratic Equations A quadratic equation has the form: a bc0 The two solutions are given by the formula: 2a Write a program with a loop that a) solves quadratic equatio...
This is in python language Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, 0, can be obtained using the following fomula: b 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no real roots. Write a program that prompts the user to enter values for a, b, and cand...
10) p. 53, problem 2.4.7. Write a Python program that uses the Quadratic Formula to calculate the real solutions to an equation in the form x 2 +bx+c=0 . Prompt the user to enter values for a, b, and c, then display the solutions. For the purposes of this assignment, you may assume that every equation will have two distinct, real solutions. Put your program in the Homework 1 folder on your K: drive. Here is a sample run of...
c++ language TECH 1211 Computer Programming Name Test 2 Hands-On-Program B Spring 2020 Write a program that uses the quadratic formula to solve quadratic equations. Background Given the format for a quadratic equations: aX? +BX+C =0 The coefficient of the X term is the number a. The coefficient of the X term is the number b. The value of c is any non-zero constant. These values can be positive, negative or zero. You can find the solution to this equation...