Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Spyder Editor
- This is a temporary script file.
- """
- import numpy
- import matplotlib.pyplot as plt
- import math
- import pandas
- excel = pandas.read_excel('datasetCh2_2019.xlsx',index_col=None,header=None)
- exfile = excel[0].values.tolist()
- x = numpy.arange(1,201)
- y = exfile
- xp=numpy.arange(1, 200, 0.1)
- for i in range(10):
- k = i+6
- J = 0
- yp = numpy.polyval(numpy.polyfit(x,y,k),xp)
- array = numpy.polyval(numpy.polyfit(x,y,k),x)-y
- for i2 in range(len(array)):
- J += math.pow(math.ceil(array[i2]),2)
- plt.plot(xp,yp)
- plt.plot(x,y,'ro')
- plt.show()
- print("k = "+str(k)+" ,J = "+str(J))
- equation2 = numpy.polyfit(x,y,15)
- xp2 = numpy.arange(1,900,1)
- yp2 = numpy.polyval(equation2,xp2)
- xq = [135.5, 255, 420.8, 820]
- yq = numpy.polyval(equation2,xq)
- plt.plot(xp2,yp2)
- plt.plot(xq,yq,'ro')
- plt.show()
- print(yq)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement