2.) Use the following data to plot a first order and second order model. I have provided code to generate a second order model, repeat this for a first order model, plot both models and the data on a single plot. Comment on which is the better fit based on the plot. X y 5 15 10 22 15 30 20 31 The following code produces a second-order model, enter this code and then repeat this for a first order model with the appropriate changes made, comment on what each line is doing.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Code in python please

2.) Use the following data to plot a first order and second order model. I have provided code to generate
a second order model, repeat this for a first order model, plot both models and the data on a single plot.
Comment on which is the better fit based on the plot.
X
у
5
15
10
22
15
30
20
31
The following code produces a second-order model, enter this code and then repeat this for a first order
model with the appropriate changes made, comment on what each line is doing.
Transcribed Image Text:2.) Use the following data to plot a first order and second order model. I have provided code to generate a second order model, repeat this for a first order model, plot both models and the data on a single plot. Comment on which is the better fit based on the plot. X у 5 15 10 22 15 30 20 31 The following code produces a second-order model, enter this code and then repeat this for a first order model with the appropriate changes made, comment on what each line is doing.
#Enter the data
x = np.array([5,10,15,20])
y = np.array([15,22,30,31])
#Quadratic Equation Model (2nd order polynomial) (y = b0 + b1*x +b2*x^2)
b = np.polyfit (x,y,2)
print("2nd order polynomial parameters:\nb2 = ",b[0]\
,"\nb1=",b[1],"\nbo=",b[2])
#Plot the model
x1 = np.linspace(5,20,100)
pylab.plot(x1, np.polyval(b,x1), c = "r", label = "2nd Order Model")
#PLot the data
pylab.scatter(x,y, c = 'k')
pylab.grid()
pylab.xlabel("x")
pylab.ylabel("y")
pylab.legend()
Transcribed Image Text:#Enter the data x = np.array([5,10,15,20]) y = np.array([15,22,30,31]) #Quadratic Equation Model (2nd order polynomial) (y = b0 + b1*x +b2*x^2) b = np.polyfit (x,y,2) print("2nd order polynomial parameters:\nb2 = ",b[0]\ ,"\nb1=",b[1],"\nbo=",b[2]) #Plot the model x1 = np.linspace(5,20,100) pylab.plot(x1, np.polyval(b,x1), c = "r", label = "2nd Order Model") #PLot the data pylab.scatter(x,y, c = 'k') pylab.grid() pylab.xlabel("x") pylab.ylabel("y") pylab.legend()
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Types of trees
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education