Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 11.20
- import numpy as np
- import numpy.linalg as la
- import matplotlib.pyplot as plt
- num_year = len(year)
- one_years = np.ones(num_year)
- xy, x, y, x2 = 0,0,0,0
- A = np.vstack([year,one_years]).T
- for i in range(num_year):
- x += year[i]
- x2 += year[i]**2
- y += percent [i]
- xy = percent[i]*year[i]
- c1, c0 = np.linalg.lstsq(A, percent)[0]
- plt.scatter(year, percent)
- plt.plot(year, c1*year + c0)
- plt.xlabel (" x axis")
- plt.ylabel("y axis")
- plt.title("graph ")
- ____________________________
- 11.21
- import numpy as np
- import numpy.linalg as la
- import matplotlib.pyplot as plt
- A = np.array([1+0*year,year,year**2]).T
- c0, c1, c2 = np.linalg.lstsq(A, percent)[0]
- plt.scatter(year, percent)
- plt.plot(year, c2*year**2 + c1*year + c0)
- plt.xlabel (" x axis")
- plt.ylabel("y axis")
- plt.title("graph ")
- _______________________
- 11.22
- import numpy as np
- import numpy.linalg as la
- import matplotlib.pyplot as pt
- y_log = np.log(y)
- coeffs = np.polyfit(x,y_log,1)
- c1 = coeffs[0]
- c0 =np.exp(coeffs[1])
- pt.plot(xp, coeffs[0]*np.exp(coeffs[1]*xp))
- pt.plot(x, y, "o")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement