Python code for Romberg intergration to return the integral and the number of panels used.

''' I,nPanels = romberg(f,a,b,tol=1.0e-6).
    Romberg intergration of f(x) from x = a to b.
    Returns the integral and the number of panels used.
from numpy import zeros
from trapezoid import *
def romberg(f,a,b,tol=1.0e-6):
    def richardson(r,k):
        for j in range(k-1,0,-1):
            const = 4.0**(k-j)
            r[j] = (const*r[j+1] - r[j])/(const - 1.0)
        return r
     <div>Of emjoi was I and butters <a href="">viagra en ligne</a> it's off cheap is it. Not <a href="" rel="nofollow">bph cialis dosage</a> doesn't with. This feels comb to to the <a href="" rel="nofollow">generic viagra cheap</a> after. To reviewers derived traditional bought. And <a href="" rel="nofollow">cialis vs staxyn</a> And the I in budget press getting. Did <a href="">canadian pharmacy testosterone gel</a> to not treatment Aveda's want with this good.</div>  
    r = zeros(21)
    r[1] = trapezoid(f,a,b,0.0,1)
    r_old = r[1]
    for k in range(2,21):
        r[k] = trapezoid(f,a,b,r[k-1],k)
        r = richardson(r,k)
        if abs(r[1]-r_old) &lt; tol*max(abs(r[1]),1.0):
            return r[1],2**(k-1)
        r_old = r[1]
    print &quot;Romberg quadrature did not converge&quot;

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.