% Interpolation!!
%
% Use points in a table of values to determine values that are not
% in the table
% Suppose we have
% x y
% -----------
% 0.4400 1.5527
% 0.4700 ??????
% 0.4800 1.6161
% 0.5200 1.6820
%
% What is y when x = 0.47?
%
% Linear interpolation
% We know that the value is going to be between y = 1.5527 and y = 1.6161
%
% Find the equation of the line between (0.44,1.5527) and (0.48,1.6161)
%
% y = mx + b
%
% Slope m = (y2-y1)/(x2-x1)
clear
x1 = 0.44;
x2 = 0.48;
y1 = 1.5527;
y2 = 1.6161;
m = (y2-y1)/(x2-x1);
% b = y - m*x where x and y are either of the (x1,y1) or (x2,y2) points
b = y1 - m*x1;
% To get y when x = 0.47, put x = 0.47 into the line equation
x3 = 0.47;
y3 = m*x3 + b
y3exact = exp(x3)
relerr = (y3-y3exact)/y3exact