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

Function method_1

maths/trapezoidal_rule.py:12–25  ·  view source on GitHub ↗
(boundary, steps)

Source from the content-addressed store, hash-verified

10from __future__ import print_function
11
12def method_1(boundary, steps):
13# "extended trapezoidal rule"
14# int(f) = dx/2 * (f1 + 2f2 + ... + fn)
15 h = (boundary[1] - boundary[0]) / steps
16 a = boundary[0]
17 b = boundary[1]
18 x_i = makePoints(a,b,h)
19 y = 0.0
20 y += (h/2.0)*f(a)
21 for i in x_i:
22 #print(i)
23 y += h*f(i)
24 y += (h/2.0)*f(b)
25 return y
26
27def makePoints(a,b,h):
28 x = a + h

Callers 1

mainFunction · 0.85

Calls 2

makePointsFunction · 0.70
fFunction · 0.70

Tested by

no test coverage detected