Talk:Romberg's method

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

a program in turbo pascal that gives us the integration of a function in 3 different ways: the Romberg's method, the trapezium rule and the simpson rule.

Not Enough Detail[edit]

This article should be classified as a stub. —The preceding unsigned comment was added by 140.160.11.159 (talk) 15:44, 3 May 2007 (UTC).[reply]

The method section needs to specify what the variables n and m are. It is ambiguous. 74.192.24.207 (talk) 05:27, 24 April 2008 (UTC)[reply]

Python source code[edit]

The python implementation is not very well written. The first problem is that the while loop is an infinite loop that is then broken out of when a certain condition is met. This is not very good practice as the loop should just run until the condition is met. Also the inline for loop finding the sums is also confusing. In general the procedure could use more comments to explain what is going on as it is hard to follow. —Preceding unsigned comment added by 75.180.15.98 (talk) 19:44, 12 November 2008 (UTC)[reply]

Source code is not particularly encouraged at Wikipedia, see WP:NOT. So I moved the code here. --Berland (talk) 20:11, 12 November 2008 (UTC)[reply]
from math import sqrt, exp, pi

def print_row(lst):
    print ' '.join('%11.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 = [[0.5 * (b - a) * (f(a) + f(b))]]  # R[0][0]
    print_row(R[0])
    n = 1
    while True:
        h =
== 
== Headline ==
 ==
 float(b - a) / 2 ** n
        R.append([None] * (n + 1))  # Add an empty row.
        # for proper limits
        R[n][0] = 0.5*R[n-1][0] + h*sum(f(a+(2*k-1)*h) for k in xrange(1, 2**(n-1)+1))
        for m in xrange(1, n+1):
            R[n][m] = R[n][m-1] + (R[n][m-1] - R[n-1][m-1]) / (4 ** m - 1)
        print_row(R[n])
        if abs(R[n][n-1] - R[n][n]) < eps:
            return R[n][n]
        n += 1

# In this example, the error function erf(1) is evaluated.
print romberg(lambda t: 2 / sqrt(pi) * exp(-t * t), 0, 1)

Python source code[edit]

Wth. While True is sometimes the best way to do it because either the loop needs to be run once before you test for a condition, or it's more efficient to break out early than after the end of an iteration. Either way it's a minor detail. I guess the in-line for loop is confusing. But I'd personally rather have some sort of source code, at all, rather than just a bunch of equations to try to deal with. I personally wish Wikipedia would include more practical or leading information, as opposed to merely factual, particularly where mathematical articles are concerned.

As for the comment about Wikipedia not encouraging source code, I looked at that WP:NOT page, and there was only one mention of 'source code' and it said that Wikipedia is not a repository for things that are *merely* collections of source code. Using some source to convey an algorithm to accompany a mathematical concept *does not* seem like merely using Wikipedia as a repository for source code, to me. I was disappointed to see it gone. I only knew it was in the talk page because I went into the history to try to find it. Not very convenient. Inhahe (talk) 21:30, 13 November 2008 (UTC)[reply]

Is the formula for R(n,m) right[edit]

The formula for R(n,m) when m=1 should be equal to Simpson's rule. If you expand the formula on this page you get (b-a)/6 (4f((a+b)/2) - f(a) - f(b)) but the correct one should be (b-a)/6 (4f((a+b)/2) + f(a) + f(b)). Or have I expanded the whole thing wrong???

Redeemer90 (talk) 03:28, 27 February 2010 (UTC)[reply]

C-language implementation[edit]

The C-language implementation is quite awkward (check for i==1 in inner loop), difficult to follow (no comments), incomplete (where is the function "Trap"), inefficient (no re-use of the function evaluations from the previous row, use of "pow" for powers of two) and the description is wrong ("trapeze" vs. "Trap").

Is there any good reason for this implementation over any other being there? Would anybody be offended if I removed/replaced this?

Cheers, pedrito - talk - 10:09 03.11.2010

I have placed an implementation that is usable. Is this acceptable. I know it is preferable to not use code of a particular language, but given that the previous example didn't work is this a viable alternative at least in the short term? KillerGardevoir (talk) 22:02, 26 October 2016 (UTC)[reply]

Robert van Engelen suggests the following: there are two errors in this C code. 1) the relative error should be compared fabs(Rc[i]-Rp[i-1]) < acc*fabs(Rp[i-1]) instead of the absolute error. 2) the returned value should be Rc[i]. Also the second inner loop can be optimized by strength-reducing n_k. Remove n_k = pow(4, j); and add n_k = 4; before this loop and and update n_k *= 4; at the end of the loop body, to update the value for the next iteration of j. — Preceding undated comment added 19:30, 18 November 2020 (UTC)

Needs a picture[edit]

This article would make a lot more sense if it had a picture of an irregular shape being measured (beneath all the scary notation this is just a way to estimate area)and a chart of the extrapolation written in simpler terms. (4MA -LA)/3, (16MA-LA) /15, (64 MA-LA)/63, ... where MA and LA stand for more accurate and less accurate respectively. This is a simple concept, but the article is so notation-heavy it would give a math professor a headache.JeffStickney (talk) 00:42, 2 August 2011 (UTC)[reply]

R(0,0)[edit]

Sorry, didn't look wel. Madyno (talk) 22:30, 20 January 2018 (UTC)[reply]