To implement Romberg’s method in MATLAB, follow these steps:
fun.a and b.n in the Romberg’s table you want to compute.R with zeros of size n by n.R, which contains the trapezoidal rule estimates of the integral with step sizes h, h/2, h/4, …, h/2^(n-1).R recursively using the formula R(i,j) = (4^(j-1) * R(i,j-1) - R(i-1,j-1)) / (4^(j-1) - 1), for i = j+1, j+2, ..., n and j = 1, 2, ..., n-1.R(n,n) of the table is the most accurate estimate of the integral.Here’s the MATLAB code for Romberg’s method:
main.m771 chars22 linesYou can use this function as follows:
main.m136 chars5 lines
gistlibby LogSnag