clear format compact %% % Let's approximate exp(x) over the interval [-1,1]. We can sample it at, % say, 40 points, and find the best-fitting straight line to that data. t = linspace(-1, 1, 40)'; y = exp(t); plot(t, y, '.') V = [t.^0 t]; c = V\y p = @(t) c(1) + c(2)*t; hold on fplot(p, [-1 1]) title('Least-squares fit to data from exp(x)') xlabel('x') ylabel('y') grid on legend('y = exp(x)', 'y = c1 + c2*x', 'location', 'best') %% % There's nothing special about 40 points. By choosing more we get closer % to the ``true'' exp(x). t = linspace(-1, 1, 200)'; y = exp(t); V = [t.^0 t]; c = V\y %% t = linspace(-1, 1, 1000)'; y = exp(t); V = [t.^0 t]; c = V\y %% % It's quite plausible that the coefficients of the best-fit line are % approaching a limit as the number of nodes goes to infinity.