summaryrefslogtreecommitdiff
path: root/docs/examples/quickstart/cythonize/integrate_cy.pyx
blob: 0bb0cd548a6424904ee1b78f4e6ed86beb9dbf25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
def f(double x):
    return x ** 2 - x


def integrate_f(double a, double b, int N):
    cdef int i
    cdef double s, dx
    s = 0
    dx = (b - a) / N
    for i in range(N):
        s += f(a + i * dx)
    return s * dx