Guest User

Untitled

a guest
Aug 17th, 2021
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import math
  3.  
  4. # Term: x^k/k!
  5. # Next term: x^(k+2)/(k+2)!
  6. # Next term/term: x^2 / (k+1) / (k+2)
  7.  
  8. def table(x):
  9.     n = 1   # terms for approximation
  10.     k = 3   # first omitted term's exponent
  11.     e = x**3 / 6    # maximum error when n = 1, k = 3
  12.     s = math.sin(x)
  13.     ep = 100 * e/s
  14.     print(n, ep, 1/ep)
  15.     while n < 10:
  16.         e = e * x**2 / (k+1) / (k+2)
  17.         k += 2
  18.         n += 1
  19.         ep = 100 * e/s
  20.         print(n, ep, 1/ep)
  21.  
  22. table(0.1)
  23.  
Advertisement
Add Comment
Please, Sign In to add comment