# runge1.r Observe Runge phenomenon with interpolation # npts = 100 # points for plotting for ( n in(c(5,7,9))) { # how many points for interpolation xi <- 4*(2*(1:n)-n-1)/(n-1) # equally spaced interpolation pts b <- 1/(1+xi*xi) # function values A <- outer(xi,(0:(n-1)),FUN="^") # vandermonde matrix print(A) b <- solve(A,b) # solution # now get ready to plot x <- 4.1*(2*(1:npts)-npts-1)/(npts-1) s <- 1/(1+x*x) # true function y <- outer(x,(0:(n-1)),FUN="^") %*% b # interpolated values print(cbind(x,s,y)) plot(c(x,x),c(s,y)) # Figure 7.1 } rm(list=ls()) q()