daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #coding: utf-8
  2. """
  3. coding with python.
  4. """
  5. import numpy
  6. import matplotlib.pyplot as plt
  7. import math
  8. import pandas
  9.  
  10. excel = pandas.read_excel('datasetCh2_2019.xlsx',index_col=None,header=None)
  11. exfile = excel[0].values.tolist()
  12. x = numpy.arange(1,201)
  13. y = exfile
  14. xp=numpy.arange(1, 200, 0.1)
  15. for i in range(10):
  16.     k = i+6
  17.     J = 0
  18.     yp = numpy.polyval(numpy.polyfit(x,y,k),xp)
  19.     array = numpy.polyval(numpy.polyfit(x,y,k),x)-y
  20.     for i2 in range(len(array)):
  21.         J += math.pow(math.ceil(array[i2]),2)
  22.     plt.plot(xp,yp)
  23.     plt.plot(x,y,'ro')
  24.     plt.show()
  25.     print("k =  "+str(k)+" ,J = "+str(J))
  26. equation2 = numpy.polyfit(x,y,15)
  27. xp2 = numpy.arange(1,900,1)
  28. yp2 = numpy.polyval(equation2,xp2)    
  29. xq = [135.5, 255,  420.8, 820]
  30. yq = numpy.polyval(equation2,xq)
  31. plt.plot(xp2,yp2)
  32. plt.plot(xq,yq,'ro')
  33. plt.show()
  34. print(yq)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top