MATLAB: The least squares quadratic function is given as Code a Matlab program

The following data are given as the results of an experiment. The least squares quadratic function is given as Code a Matlab program that calculates the total squared error (E).
x = [5.435 4.635 3.835 3.035 2.325 1.435 0.635]
y = [1.00 1.28 1.70 2.20 2.97 4.35 7.50 ]

Best Answer

I’m not certain what you want to do.
Here is one possibility:
x = [5.435 4.635 3.835 3.035 2.325 1.435 0.635];
y = [1.00 1.28 1.70 2.20 2.97 4.35 7.50 ];
p = polyfit(x, y, 2); % Quadratic Function Fit
v = polyval(p, x); % Evaluate
TSE = sum((v - y).^2); % Total Squared Error
figure(1)
plot(x, y, 'bp')
hold on
plot(x, v, '-r')
hold off
grid