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
- def wartosc(f,x=0):
- return eval(f,{'x':x})
- print "Funkcja 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)
- y1=np.arange(xmin,xmax,0.1)
- c=d=e=f=0
- for i in range(0,len(x)):
- c += x[i]*y[i]
- d += x[i]
- e += y[i]
- f += x[i]**2
- y[i]=wartosc(funkcja,x[i]+sp.rand())
- plt.plot(x[i],y[i],"ro", ms=5)
- plt.title("Info")
- n=len(x)
- a=((n*c-d*e)/(n*f-d**2))
- b=((f*e-d*c)/(n*f-d**2))
- for i in range(0,len(x)):
- y1[i]=wartosc(funkcja,x[i])
- line = plt.plot(x,y1)
- plt.show()
- 51
- import numpy as np
- import scipy as sp
- import matplotlib.pyplot as plt
- def wartosc (f,x=0):
- return eval (f,{'x':x})
- print "funkcja 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)
- y1=np.arange(xmin,xmax,0.1)
- c=d=e=f=0
- for i in range (0,len(x)):
- c += x[i]*y[i]
- d += x[i]
- e += y[i]
- f += x[i]**2
- y[i]=wartosc(funkcja,x[i])+sp.rand()
- plt.plot(x[i],y[i],"ro",ms=5)
- plt.title("Info")
- n=len(x)
- #a1=((n*c-d*e)/(n*f-d**2))
- #b1=((f*e-d*c)/(n*f-d**2))
- #funkcja2=a1+"*x+"+b1
- a=((n*c-d*e)/(n*f-d**2))
- b=((f*e-d*c)/(n*f-d**2))
- for i in range(0,len(x)):
- y1[i]=wartosc(funkcja,x[i])
- line = plt.plot(x,y1)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement