# # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- v = c( 2, 4, -2, 6, -4, 8, -2 ) print( sum( v^2 ) ) x = (-0.5)^seq(0,7) w = c( 0, 2, 4, -2, 6, -4, 8, -2 ) a0_hat = sum( x * w )/sum( x * x ) print( a0_hat ) # compute the residual of this approximation: res = w - a0_hat * x print( sum( res^2 ) )