I am trying to write a matlab function that calculates the coefficient of thermal expansion of water from a given temperature. From what I understand the thermal expansion coefficient is calculated as the degree of expansion divided by the change in temperature, expressing the tendency of a fluid to change in volume with a change in temperature.
The following code calculates this in matlab:
T = 20; % initial temperature
dT = 0.001; % change in temperature °C
V = 1; % volume m^3
rho1 = waterDensity(T); % density of temperature
rho2 = waterDensity(T+dT);% density of second temperature
V2 = rho1./rho2;
alpha = (V2-V)/dT; % coefficient of thermal expansion in deg C-1
where waterDensity is an external function that calculates the density of water in kgm-3 from a given temperature. Here, I'm having trouble making sense of this, mostly I don't understand why we need the line that starts with V2. I would have though that if mass is conserved the volume is given by the density so alpha should be calculated by the change in density divided by the change in temperature i.e.
alpha = (rho - rho1) ./ dT
Could anyone explain to me why this isn't the case.
I know that the first method works because it gives the same result as:
alpha = 1.6e-5 + 9.6e-6 .* T;
which is commonly used in the literature.