Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1.  
  2. def f(x):
  3. if(x == 0):
  4. return 1.04
  5. if(x == 0.25):
  6. return 0.37
  7. if(x == 0.5):
  8. return 0.38
  9. if(x == 0.75):
  10. return 1.49
  11. if(x == 1.0):
  12. return 1.08
  13. if(x == 1.25):
  14. return 0.13
  15. if(x == 1.5):
  16. return 0.64
  17. if(x == 1.75):
  18. return 0.84
  19. if(x == 2):
  20. return 0.12
  21.  
  22. def integrateSimpson(f,a, b, n):
  23. result = f(a)+f(b)
  24. h = (b-a)/n
  25. x = 0.25
  26. while x < 2.0:
  27. if(x%2 == 0):
  28. result += 2*f(a+x*h)
  29. else:
  30. result += 4*f(a+x*h)
  31. x += h
  32. return result*h/3
  33.  
  34. print(integrateSimpson(f,0, 2.0, 8))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement