Advertisement
yukcheong

Graph and equation

Apr 19th, 2020
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. import scipy.optimize as opt
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. from math import log
  5.  
  6.  
  7. def f(variables) :
  8.     (x,y) = variables
  9.  
  10.     first_eq = 32.73428 + (35094.08 - 32.73428)/(1 + (x/23.12766)**1.021899)-y
  11.     second_eq = 2.6186666666666683*x + 801.2666666666664 -y
  12.     return [first_eq, second_eq]
  13.  
  14.  
  15. solution = opt.fsolve(f, (0.1,1) )
  16. print solution
  17.  
  18. ax = plt.subplot()
  19. xvalue=[]
  20.  
  21. global xvalue
  22. num = 200
  23. for i in range(10) :
  24.     if i < 4:
  25.         xvalue.append(num)
  26.         num += 100
  27.     else :
  28.         xvalue.append(num)
  29.         num += 200
  30.    
  31.  
  32. x = np.array(xvalue)
  33. xdetails = np.arange(min(x)-1, max(x)+1, .01)
  34. y = np.array([ 3513, 2434, 1809, 1497, 1236, 970, 771, 628, 542, 498])
  35. y1 = np.array([ 1432, 1626, 1847, 2038, 2285, 2791, 3554, 3873, 4471, 5045])
  36. m, c = np.polyfit(x, y1, 1)
  37.  
  38. #y = 529330.5*x^-0.9458724
  39. #y = 32.73428 + (35094.08 - 32.73428)/(1 + (x/23.12766)^1.021899)
  40. #y = 12.52401 + (3513.033 - 12.52401)/(1 + (x/204.072)^291.157)^0.00332465
  41.  
  42. plt.plot(x, m*x+c ,label = 'test')
  43. plt.plot(xdetails, 32.73428 + (35094.08 - 32.73428)/(1 + (xdetails/23.12766)**1.021899))
  44. plt.plot(x, y, 'o')
  45. plt.plot(x, y1, 'o')
  46. plt.grid(linestyle='--')
  47. plt.legend()
  48.  
  49. ax.spines['top'].set_visible(False)
  50. ax.spines['right'].set_visible(False)
  51.  
  52. plt.title('test')
  53. plt.xlabel('Test', labelpad=10)
  54. plt.ylabel('Test', labelpad=10)
  55. #plt.text(1, -7,'matplotlib', horizontalalignment='left',verticalalignment='center')
  56.  
  57. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement