Romberg's Method - Implementation

Implementation

Here is an example of a computer implementation of the Romberg method (in the C programming language). It needs one vector and one variable, as well as a sub-routine trapeze:

#include #include #include #define MAX 6 int main { double s; int i,k; double var ; for (i = 1; i< MAX; i++) s = 1; for (k=1; k< MAX; k++) { for (i=1; i <=k; i++) { if (i==1) { var = s; s = Trap(0, 1, pow(2, k-1)); // sub-routine trapeze } // integrated from 0 and 1 /* pow is the number of subdivisions*/ else { s= ( pow(4, i-1)*s-var )/(pow(4, i-1) - 1); var = s; s= s; } } for (i=1; i <=k; i++) printf (" %f ", s); printf ("\n"); } return 0; }

Read more about this topic:  Romberg's Method