Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def f(x):
- if(x == 0):
- return 1.04
- if(x == 0.25):
- return 0.37
- if(x == 0.5):
- return 0.38
- if(x == 0.75):
- return 1.49
- if(x == 1.0):
- return 1.08
- if(x == 1.25):
- return 0.13
- if(x == 1.5):
- return 0.64
- if(x == 1.75):
- return 0.84
- if(x == 2):
- return 0.12
- def integrateSimpson(f,a, b, n):
- result = f(a)+f(b)
- h = (b-a)/n
- x = 0.25
- while x < 2.0:
- if(x%2 == 0):
- result += 2*f(a+x*h)
- else:
- result += 4*f(a+x*h)
- x += h
- return result*h/3
- print(integrateSimpson(f,0, 2.0, 8))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement