Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from numpy import arange
- from math import fabs
- def lagranz(x, y, t):
- z = 0
- for j in range(len(y)):
- p = 1
- for i in range(len(x)):
- if i != j:
- p *= (t-x[i])/(x[j]-x[i])
- z += p * y[j]
- return z
- def tabulate_point(x, e):
- a = x
- y = a
- n = 0
- while fabs(a) > e:
- q = - pow(x, 2) * (2*n+1) / (pow(2*n+3, 2)*(2*n+2))
- a = q * a
- y += a
- n += 1
- return y
- def tabulation(a, b, count, e):
- x_points = []
- f_arr = []
- h = (b - a) / count
- for x in arange(a, b, h):
- f = tabulate_point(x, e)
- x_points.append(x)
- f_arr.append(f)
- return x_points, f_arr
- x_arr, y_arr = tabulation(0, 4, 10, pow(10, -6))
- x_arr1, y_arr1 = tabulation(0, 4, 5, pow(10, -6))
- for i, j in zip(x_arr, y_arr):
- z = lagranz(x_arr1, y_arr1, i)
- print('%.1f : %f : %f' % (i, z, z - j))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement