% =========================================================================
% Script for calculation of Cp(T) for water at 1 MPa
% 
% References:
%   i) Handbook of Chemistry and Physics, 85th ed., CRC Press, 2005
%
% H. Smedsrud, 2007
% =========================================================================

clc
clear all
close all

% Temperatures for water (converted from the ITS-90 scale) [C]
T_list = [0.04;26.88;51.88;76.88;101.88;126.88;176.88;179.91];

% Heat capacities for water [J/g*C]
Cp_list = [4.2150;4.1781;4.1798;4.1925;4.2158;4.2535;4.3924;4.4045];

% Want a model on the form Cp(T) = alfa + beta*T + gamma*T^2

% Initial values of the parameters:
par0 = [4.2117 -0.0013 0];

model = @Cp_model;
[par,R,J,sigma,MSE] = nlinfit(T_list,Cp_list,model,par0);
format long
parameters = par
format short
residuals = R
Cp_fit = Cp_model(par,T_list);

% Heat capacity for water at 1 MPa
plot(T_list,Cp_list,T_list,Cp_fit)
legend('Experimental data','Predicted data')
xlabel('Temperature [°C]')
ylabel('Specific heat capacity [J/g*°C]')