Python function to find the order of a quadrature formula

312 Views Asked by At

I am required to code a function that finds the order of a given quadrature formula and then apply the function to the mid-point rule and the two point Gauss quadrature formula.

I have the following theorem to work with-

Let $b_i$ and $c_i$ be the weights and nodes of a quadrature formula for $i=1,...,s$ Then it holds that if $\sum_{i=1}^{s} b_ic_i^{q-1} = \frac{1}{q},$ $q=1,...,r$ for $r\le k,$ then the quadrature method is of order k.

And this is my python code

def order (weights,nodes):
    for q in range(1,len(weights)+10):
        sum=0
        for i in range(len(weights)):
            sum+=weights[i]*nodes[i]**(q-1)
        if sum!=1/q:
            print(q)
            break

It works for the midpoint rule with weights=[1/2,1/2] and nodes=[0,1], but not for the two point Gauss with nodes $=[-\frac{1}{\sqrt{3}},\frac{1}{\sqrt{3}}]$ and weights=[1,1].

Any suggestion on what I am doing wrong greatly appreciated.