summaryrefslogtreecommitdiff
path: root/Demos/integrate2.pyx
blob: 9f8ccaa7ad1319126f471227e3aa46f11efd35a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
# cython: language_level=3

cdef double f(double x) except? -2:
    return x**2-x


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