%% Linear Least Squares
% Sample linear fit to data points

T=[300 400 500 600 700 800 900 1000]';
Cp=[1.0045 1.0134 1.0296 1.0507 1.0743 1.0984 1.1212 1.1410]';

A=[size(T,1) sum(T); sum(T) sum(T.^2)];
c=[sum(Cp) sum(T.*Cp)]';

b=A\c;

Tc=200:1:1200;

figure(1);

plot(Tc,b(1)+b(2).*Tc);
hold on;
scatter(T,Cp);
xlabel('Temperature (K)');
ylabel('Cp (J/gK)');

P=polyfit(T,Cp,2);
figure(2);
plot(Tc,polyval(P,Tc)); hold on; scatter(T,Cp);
xlabel('Temperature (K)');
ylabel('Cp (J/gK)');