Advertisement
myloyo

№1 Интерполяционный многочлен в общем виде (надо исправить код)

Dec 12th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import numpy as np
  2.  
  3.  
  4. def init(points):
  5.     n = len(points)
  6.     sole = np.zeros((n, n + 1))
  7.  
  8.     # Populate the augmented matrix
  9.     for i in range(n):
  10.         sole[i, -1] = points[i][1]
  11.         x = 1
  12.         for j in range(n - 1, -1, -1):
  13.             sole[i, j] = x
  14.             x *= points[i][0]
  15.  
  16.     return sole
  17.  
  18.  
  19. def solve():
  20.     # Define the points (x, y)
  21.     points = [(0, 8), (1, 9), (2, 16), (3, 43)]
  22.  
  23.     # Print the x values
  24.     print("\t".join(f"{x[0]:.1f}" for x in points))
  25.  
  26.     # Print the y values
  27.     print("\t".join(f"{x[1]:.1f}" for x in points))
  28.     print()
  29.  
  30.     # Initialize the augmented matrix
  31.     sole = init(points)
  32.  
  33.     # Print the augmented matrix
  34.     for row in sole:
  35.         print("\t".join(f"{x:.3f}" for x in row))
  36.  
  37.  
  38. if __name__ == "__main__":
  39.     solve()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement