Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- Y = [44.22, 60.87, 77.74, 94.62, 111.34, 128.43, 145.12, 161.96, 178.79, 195.6]
- X = [10, 14, 18, 22, 26, 30, 34, 38, 42, 46]
- n = 10
- xy = 0
- x = 0
- y = 0
- x2 = 0
- for i in range(10):
- x += X[i]
- y += Y[i]
- xy += X[i] * Y[i]
- x2 += X[i]**2
- x /= n
- y /= n
- xy /= n
- x2 /= n
- k = round((xy - x * y) / (x2 - x ** 2), 2)
- b = round(y - k * x, 2)
- print("k b ", k, b)
- def f(x):
- return k * x + b
- for i in range(10):
- print(i, f(X[i]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement