Advertisement
Dantenerosas

Untitled

May 16th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. def calc_integral(ys, h, a, b):
  2.     func = lambda x: calc_polynominal(ys, x, h)
  3.     #n = 7
  4.     #k = 17280
  5.     #H0 = 751
  6.     #H1 = 3577
  7.     #H2 = 1323
  8.     #H3 = 2989
  9.     #coeff_cotes = (Decimal(H0/k), Decimal(H1/k),
  10.     #               Decimal(H2/k), Decimal(H3/k),
  11.     #               Decimal(H3/k), Decimal(H2/k),
  12.     #               Decimal(H1/k), Decimal(H0/k))
  13.     n = 8
  14.     k = 28350
  15.     H0 = 939
  16.     H1 = 5888
  17.     H2 = -928
  18.     H3 = 10496
  19.     H4 = -4540
  20.     coeff_cotes = (Decimal(H0/k), Decimal(H1/k),
  21.                Decimal(H2/k), Decimal(H3/k), Decimal(H4/k),
  22.                Decimal(H3/k), Decimal(H2/k),
  23.                Decimal(H1/k), Decimal(H0/k))
  24.     result = 0
  25.     h_int = Decimal((b-a)/Decimal(n))
  26.     x = a
  27.     i = 0
  28.     while x <= b:
  29.         result += func(x) * coeff_cotes[i]
  30.         print(i, x, result)
  31.         x += h_int
  32.         i += 1
  33.     return Decimal(b-a)*result
  34.  
  35.  
  36. def calc_rn(a, b, h):
  37.     y_7d = lambda x_f: Decimal(-(92160*(-1+84*x_f**2-560*x_f**4+448*x_f**6))/(1+4*x_f**2)**7)
  38.     pn = Decimal(1)
  39.     n = 6
  40.     h_int = Decimal((b-a)/Decimal(n))
  41.     x_n = a
  42.     y1 = y_7d(a)
  43.     y2 = y_7d(b)
  44.     if y1 > y2:
  45.         x = a
  46.     else:
  47.         x = b
  48.     for i in range(n):
  49.         pn *= x - x_n
  50.         x_n += h_int
  51.     if y1 > y2:
  52.         return (y1*pn)/Decimal(math.factorial(n))
  53.     else:
  54.         return (y2*pn)/Decimal(math.factorial(n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement