Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pol_coef(n, val_list):
- coef_list = []
- matrix = [ [] for i in range(n)]
- #Matrix for divided differences
- for i in range(n):
- matrix[i].append(float(val_list[i]))
- #starting point for divided differences - bottom up
- for j in range(1,n):
- for i in range(j,n):
- matrix[i].append( (matrix[i][j-1] - matrix[i-1][j-1]) / (j) )
- #Completing the divided Differences
- for i in range(0,n):
- coef_list.append((matrix[i][i]))
- return(coef_list)
- def horner_print(n, m, coef_list):
- out = []
- for k in range(n, n+m):
- val = coef_list[n-1]
- for i in [(n-j) for j in range(2, n+1) ]:
- val = val*(k-i) + coef_list[i]
- out.append(str(round(val)))
- print(" ".join(out))
- for times in range(int(input())):
- n_m = input().split(" ")
- val_list = input().split(" ")
- horner_print( int(n_m[0]), int(n_m[1]), pol_coef( int(n_m[0]), val_list) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement