MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / method_2

Function method_2

maths/simpson_rule.py:14–28  ·  view source on GitHub ↗
(boundary, steps)

Source from the content-addressed store, hash-verified

12
13
14def method_2(boundary, steps):
15# "Simpson Rule"
16# int(f) = delta_x/2 * (b-a)/3*(f1 + 4f2 + 2f_3 + ... + fn)
17 h = (boundary[1] - boundary[0]) / steps
18 a = boundary[0]
19 b = boundary[1]
20 x_i = makePoints(a,b,h)
21 y = 0.0
22 y += (h/3.0)*f(a)
23 cnt = 2
24 for i in x_i:
25 y += (h/3)*(4-2*(cnt%2))*f(i)
26 cnt += 1
27 y += (h/3.0)*f(b)
28 return y
29
30def makePoints(a,b,h):
31 x = a + h

Callers 1

mainFunction · 0.85

Calls 2

makePointsFunction · 0.70
fFunction · 0.70

Tested by

no test coverage detected