Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import scipy as sp
- import matplotlib.pyplot as plt
- from scipy.stats import linregress as lr
- def wartosc(f,x=0):
- return eval(f,{'x':x})
- print "Funcja y=a*x+b"
- a=raw_input("Podaj a=")
- b=raw_input("Podaj b=")
- funkcja=a+"*x+"+b
- xmin=-1
- xmax=1
- x=np.arange(xmin,xmax,0.1)
- y=np.arange(xmin,xmax,0.1)
- for i in range(0,len(x)):
- y[i]=wartosc(funkcja,x[i])+sp.rand()
- plt.plot(x[i],y[i],"ro",ms=5)
- fit = np.polyfit(x,y,1)
- fit_fn = np.poly1d(fit)
- plt.plot(x,y, 'yo', x, fit_fn(x))
- plt.title("wykres funkcji na podstawie regresji liniowej")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement