Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Spyder Editor
  4.  
  5. This is a temporary script file.
  6. """
  7. import numpy
  8. import matplotlib.pyplot as plt
  9. import math
  10. import pandas
  11.  
  12. excel = pandas.read_excel('datasetCh2_2019.xlsx',index_col=None,header=None)
  13. exfile = excel[0].values.tolist()
  14. x = numpy.arange(1,201)
  15. y = exfile
  16. xp=numpy.arange(1, 200, 0.1)
  17. for i in range(10):
  18.     k = i+6
  19.     J = 0
  20.     yp = numpy.polyval(numpy.polyfit(x,y,k),xp)
  21.     array = numpy.polyval(numpy.polyfit(x,y,k),x)-y
  22.     for i2 in range(len(array)):
  23.         J += math.pow(math.ceil(array[i2]),2)
  24.     plt.plot(xp,yp)
  25.     plt.plot(x,y,'ro')
  26.     plt.show()
  27.     print("k =  "+str(k)+" ,J = "+str(J))
  28. equation2 = numpy.polyfit(x,y,15)
  29. xp2 = numpy.arange(1,900,1)
  30. yp2 = numpy.polyval(equation2,xp2)    
  31. xq = [135.5, 255,  420.8, 820]
  32. yq = numpy.polyval(equation2,xq)
  33. plt.plot(xp2,yp2)
  34. plt.plot(xq,yq,'ro')
  35. plt.show()
  36. print(yq)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement