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)
| 34 | |
| 35 | |
| 36 | def 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 | |
| 65 | def f(x): |