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 1.42 KB | None | 0 0
  1. import numpy as np
  2. import scipy as sp
  3. import matplotlib.pyplot as plt
  4.  
  5. def wartosc(f,x=0):
  6. return eval(f,{'x':x})
  7. print "Funkcja 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.  
  16. y1=np.arange(xmin,xmax,0.1)
  17. c=d=e=f=0
  18. for i in range(0,len(x)):
  19. c += x[i]*y[i]
  20. d += x[i]
  21. e += y[i]
  22. f += x[i]**2
  23. y[i]=wartosc(funkcja,x[i]+sp.rand())
  24. plt.plot(x[i],y[i],"ro", ms=5)
  25. plt.title("Info")
  26.  
  27. n=len(x)
  28. a=((n*c-d*e)/(n*f-d**2))
  29. b=((f*e-d*c)/(n*f-d**2))
  30. for i in range(0,len(x)):
  31. y1[i]=wartosc(funkcja,x[i])
  32. line = plt.plot(x,y1)
  33.  
  34.  
  35. plt.show()
  36.  
  37. 51
  38.  
  39. import numpy as np
  40. import scipy as sp
  41. import matplotlib.pyplot as plt
  42.  
  43. def wartosc (f,x=0):
  44. return eval (f,{'x':x})
  45. print "funkcja y=a*x+b "
  46. a=raw_input("Podaj a:")
  47. b=raw_input("Podaj b:")
  48. funkcja= a+"*x+"+b
  49. xmin=-1
  50. xmax=1
  51. x=np.arange(xmin,xmax,0.1)
  52. y=np.arange(xmin,xmax,0.1)
  53. y1=np.arange(xmin,xmax,0.1)
  54. c=d=e=f=0
  55. for i in range (0,len(x)):
  56. c += x[i]*y[i]
  57. d += x[i]
  58. e += y[i]
  59. f += x[i]**2
  60. y[i]=wartosc(funkcja,x[i])+sp.rand()
  61. plt.plot(x[i],y[i],"ro",ms=5)
  62. plt.title("Info")
  63.  
  64. n=len(x)
  65. #a1=((n*c-d*e)/(n*f-d**2))
  66. #b1=((f*e-d*c)/(n*f-d**2))
  67. #funkcja2=a1+"*x+"+b1
  68. a=((n*c-d*e)/(n*f-d**2))
  69. b=((f*e-d*c)/(n*f-d**2))
  70. for i in range(0,len(x)):
  71. y1[i]=wartosc(funkcja,x[i])
  72. line = plt.plot(x,y1)
  73. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement