% Construct the table for exp(x) using linear interp % Note that nodes(1) is 0, nodes(2) = h, nodes(3) = 2*h % since subscripts begin at 1 in matlab h = 0.001 nodes = 0:h:1; expTable = exp(nodes); % Specify a value x between nodes % and determine which linear segment it is in x = 0.51515 k = floor( (x-0) / h) x0 = nodes(k+1) % this is node k y0 = expTable(k+1) x1 = nodes(k+2) % this is node k + 1 y1 = expTable(k+2) % interpolated value yi is yi = y0*(x-x1)/(x0-x1) + y1*(x-x0)/(x1-x0) % Interpolation error is err = yi - exp(x)