Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import numpy as np
  2. import scipy as sp
  3. import matplotlib.pyplot as plt
  4. from scipy.stats import linregress as lr
  5. def wartosc(f,x=0):
  6. return eval(f,{'x':x})
  7. print "Funcja y=a*x+b"
  8. a=raw_input("Podaj a=")
  9. b=raw_input("Podaj b=")
  10. funkcja=a+"*x+"+b
  11. xmin=-1
  12. xmax=1
  13. x=np.arange(xmin,xmax,0.1)
  14. y=np.arange(xmin,xmax,0.1)
  15. for i in range(0,len(x)):
  16. y[i]=wartosc(funkcja,x[i])+sp.rand()
  17. plt.plot(x[i],y[i],"ro",ms=5)
  18.  
  19. fit = np.polyfit(x,y,1)
  20. fit_fn = np.poly1d(fit)
  21.  
  22. plt.plot(x,y, 'yo', x, fit_fn(x))
  23. plt.title("wykres funkcji na podstawie regresji liniowej")
  24. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement