data_xx = [1 2 4 5 6 7];
data_yy = [10 6 3 4 6 10];

figure(1); clf; hold on;
plot(data_xx, data_yy, 'x:');

% compute sum(x^4), sum(x^3), sum(x^2), sum(x^1), sum(x^0)
x4 = sum(data_xx .^ 4);
x3 = sum(data_xx .^ 3);
x2 = sum(data_xx .^ 2);
x1 = sum(data_xx .^ 1);
x0 = sum(data_xx .^ 0);

% compute sum(x^2*y), sum(x*y), sum(y)
y2 = sum(data_xx .^ 2 .* data_yy);
y1 = sum(data_xx .* data_yy);
y0 = sum(data_yy);

% construct A and y
A = [ x4 x3 x2;  x3 x2 x1;  x2 x1 x0 ];
y = [ y2;  y1;  y0];

% solve for least square solution with a ax^2 + bx + c = y
x = A^-1 * y;
a = x(1);
b = x(2);
c = x(3);



eqn_xx = min(data_xx):0.1:max(data_xx);
eqn_yy = (a * eqn_xx .^ 2) + (b * eqn_xx) + c;
plot(eqn_xx, eqn_yy, 'r');
