MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / make_points

Function make_points

maths/trapezoidal_rule.py:36–62  ·  view source on GitHub ↗

Generates points between a and b with step size h for trapezoidal integration. :param a: The lower bound of integration :param b: The upper bound of integration :param h: The step size :yield: The next x-value in the range (a, b) >>> list(make_points(0, 1, 0.1)) # docte

(a, b, h)

Source from the content-addressed store, hash-verified

34
35
36def make_points(a, b, h):
37 """
38 Generates points between a and b with step size h for trapezoidal integration.
39
40 :param a: The lower bound of integration
41 :param b: The upper bound of integration
42 :param h: The step size
43 :yield: The next x-value in the range (a, b)
44
45 >>> list(make_points(0, 1, 0.1)) # doctest: +NORMALIZE_WHITESPACE
46 [0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, \
47 0.8999999999999999]
48 >>> list(make_points(0, 10, 2.5))
49 [2.5, 5.0, 7.5]
50 >>> list(make_points(0, 10, 2))
51 [2, 4, 6, 8]
52 >>> list(make_points(1, 21, 5))
53 [6, 11, 16]
54 >>> list(make_points(1, 5, 2))
55 [3]
56 >>> list(make_points(1, 4, 3))
57 []
58 """
59 x = a + h
60 while x <= (b - h):
61 yield x
62 x += h
63
64
65def f(x):

Callers 1

trapezoidal_ruleFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected