Using the data of Example 6.2.2, find and plot the parabola \(y = cx^2+dx+e\) that fits the data best in the sense of least squares.
Answer.
x = [-1, 0, 2, 3, 4, 7]'; y = [9, 8, 5, 5, 3, 1]'; A = [x.^2, x, x.^0]; z = A\y; xx = linspace(min(x), max(x), 500)'; yy = [xx.^2, xx, xx.^0]*z; plot(xx, yy, 'b', x, y, 'r*')
Explanation: the only modification that we need is to add a column with the squares of x-values. In general, this process allows us to fit a function of the form \(c_1 f_1(x) + c_2 f_2(x) + \cdots + c_n f_n(x) \) where \(f_1, f_2, \dots, f_n\) are given functions and \(c_1, c_2, \dots, c_n\) are coefficients (parameters) to be determined.
