(boundary, steps)
| 12 | |
| 13 | |
| 14 | def 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 | |
| 30 | def makePoints(a,b,h): |
| 31 | x = a + h |
no test coverage detected