Computer science Answers 9/10/2020

in #answers4 years ago

The code part a is:

def slope(x, y):
N = len(x) # store the length of list
xy = [] # storing x*y
x2 = [] # storing square of x
for i in range(N):
xy.append(x[i] * y[i])
x2.append(x[i] * x[i])
a = sum(xy) / sum(x2) # formula for calculation slope is summation of xy divided by summation of square of x
return a

x = [0, 1, 2]
y = [1, 1, 2]
print('The slope is: {}'.format(slope(x, y)))

The code for part b is:

def line(x, y):
N = len(x) # store the length of list
xy = [] # storing x*y
x2 = [] # storing square of x
for i in range(N):
xy.append(x[i] * y[i])
x2.append(x[i] * x[i])
a = (N * sum(xy) - sum(x) * sum(y)) / (N * sum(x2) - sum(x) * sum(x)) # formula for calculation slope
b = (sum(y) - a * sum(x)) / N # formula for calculating intercept
return a, b

x = [0, 1, 2]
y = [1, 1, 2]
a, b = line(x, y)
print('The slope is: {}\nThe intercept is: {}'.format(a, b))

The formula to calculate the slope in part b is:

1599626512199_image.png

The formula to calculate the intercept in part b is:

1599626610671_image.png

The calculation part of slope in part b is:

1599659899646_WhatsAppImage2020-09-09at7.26.49PM.png

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.029
BTC 76343.25
ETH 3042.42
USDT 1.00
SBD 2.62