%----------------------------------------------------------------------- % Regression of Antoine coefficients by minimizing sse. % Estimate the Antoine constants of water by fitting the given steam data % to the equation % Psat = exp( A-B/(T+C)) % where Psat is the saturation pressure in psia and T is temperature in øF. % Programming Note: call fmins (old) or fminsearch; need steamrf.m (which specifies sse) % Instructor: Nam Sun Wang %----------------------------------------------------------------------- % Start fresh clear all % Extend data x and y to external subroutines global T P % Program header ------------------------------------------------------- disp('Nonlinear regression of Antoine coefficients of water') disp(' Psat = exp(A-B/(T+C))') % Read data from a file ------------------------------------------------ load steam.dat; T = steam(:,1); P = steam(:,2); % Initial guess -------------------------------------------------------- param(1) = 15.; param(2) = 10000.; param(3) = 460.; % Call a routine (fmins or fminsearch) to find the parameters ------------------------ % param = fmins('steamrf', param); ... obsolete param = fminsearch('steamrf', param); % Print the coefficients ----------------------------------------------- A = param(1); B = param(2); C = param(3); disp('The coefficients are:') disp([' A = ', num2str(A) ]) disp([' B = ', num2str(B) ]) disp([' C = ', num2str(C) ]) disp(['The value of sse is: ', num2str(steamrf(param)) ]) % Generate the fitted function Pregress = exp(A-B./(T+C)); % Plot and compare results plot(T, P, 'o', T, Pregress, '-')