romberg <- function ( f, a, b, m, tab = FALSE ) #*****************************************************************************80 # ## romberg computes the intercept and slope of a line. # # Licensing: # # Copyright 2016 James P. Howard, II # # The computer code and data files on this web page are distributed under # https://opensource.org/licenses/BSD-2-Clause, the BSD-2-Clause license. # # Modified: # # 08 March 2020 # # Author: # # Original R code by James Howard; # Modifications by John Burkardt. # # Reference: # # James Howard, # Computational Methods for Numerical Analysis with R, # CRC Press, 2017, # ISBN13: 978-1-4987-2363-3. # { source ( "/home/burkardt/public_html/r_src/trap/trap.R" ) R <- matrix ( NA, nrow = m, ncol = m ) R[1,1] <- trap ( f, a, b, m = 1 ) for ( j in 2 : m ) { R[j,1] <- trap ( f, a, b, m = 2^(j-1) ) for ( k in 2 : j ) { k4 = 4 ^ ( k - 1 ) R[j,k] <- k4 * R[j,k-1] - R[j-1,k-1] R[j,k] <- R[j,k] / ( k4 - 1 ) } } if ( tab == TRUE ) { return ( R ) } else { return ( R[m,m] ) } }