MATLAB: How to generate Best fit second order polynomial equation from MATLAB for given data

best fitcurve fittingpolynomialsecond order

Hi all can anybody tell me how to generate above equation for this x and y data using MATLAB ? x,y coordinates are 6,460 10,380 12,300 14,180

Best Answer

This works:
xy = [6 460; 10 380; 12 300; 14 180]; % Data
b = polyfit(xy(:,1), xy(:,2), 2); % Estimate Parameters For Quadratic Fit
y_fit = polyval(b, xy(:,1)); % Evaluate Fitted Curve
figure(1)
plot(xy(:,1), xy(:,2), 'pg')
hold on
plot(xy(:,1), y_fit, '-r')
hold off
grid
axis([5 15 ylim])