אבל משום מה עכשיו לא רואים כ את כל מה שהיה בתוך סוגריים מרובעות...def print_row( lst ): print ' '.join( '.8f' % x for x in lst )
def romberg( f, a, b, eps = 1E-8 ):
"""Approximate the definite integral of f from a to b by Romberg's method,
eps is the desired accuracy."""
R=
R.append() # R
print_row(R)
n=1
while True:
h = float(b-a)/2**n
R.append( (n 1)* )
R = 0.5*R h*sum(f(a (2*k-1)*h) for k in range(1,2**(n-1) 1)) # for proper limits
for m in range(1,n 1):
R = R ( R-R )/( 4**m - 1 )
print_row(R)
if abs(R-R)<eps: return R
n =1
from math import *
# In this example, the error function erf(1) is evaluated.
print romberg( lambda t: 2/sqrt(pi)*exp( -t*t ), 0, 1 )