function P3_03D2 clear, clc, format short g, format compact xyData=[85.47 2.48E+07 90 2.46E+07 100 2.42E+07 110 2.37E+07 120 2.33E+07 130 2.29E+07 140 2.25E+07 150 2.21E+07 160 2.17E+07 170 2.13E+07 180 2.09E+07 190 2.05E+07 200 2.01E+07 210 1.97E+07 220 1.93E+07 231.07 1.88E+07 240 1.83E+07 250 1.78E+07 260 1.73E+07 270 1.67E+07 280 1.61E+07 290 1.54E+07 300 1.46E+07 310 1.38E+07 320 1.28E+07 330 1.18E+07 340 1.05E+07 350 8.95E+06 360 6.81E+06]; X=xyData(:,1); m=size(X,1); %Determine the number of data points Y=xyData(:,2); prob_title = ([' Heat of Vaporization of Propane, NlN Reg.']); dep_var_name=['Heat of Vaporization (J/kmol) ']; ind_var_name=['Temperature (K)']; parm=[2.926e6 0.3765]; npar=size(parm,2); % Determine the number of the parameters options=optimset('MaxFunEvals',1000); % Change the default value for MaxFunEvals Beta=fminsearch(@NonlinFun,parm,options,X,Y); % Find optimal parameters using fminsearch [f,Ycalc]=NonlinFun(Beta,X,Y); % Compute Y (calculated) at the optimum disp([' Results,' prob_title ]); Res=[]; for i=1:npar Res=[Res; i Beta(i)]; end disp(' Parameter No. Value '); disp(Res); s2=sum((Y-Ycalc)'*(Y-Ycalc))/(m-npar); %variance disp([' Variance ', num2str(s2)]); ymean=mean(Y); R2=(Ycalc-ymean)'*(Ycalc-ymean)/((Y-ymean)'*(Y-ymean));%linear correlation coefficient disp([' Correlation Coefficient ', num2str(R2)]) plot(Y,Y-Ycalc,'*') % Residual plot title(['Residual Plot, ' prob_title ]) xlabel([dep_var_name '(Measured)']) ylabel('Residual') pause plot(X,Ycalc,'r-',X,Y,'b+' ) %Plot of experimental and calculated data title(['Calculated/Experimental Data ' prob_title]) xlabel([ind_var_name]) ylabel([dep_var_name]) function [f,Ycalc]=NonlinFun(parm,X,Y) A=parm(1); n=parm(2); for i=1:size(X,1); Ycalc(i,1)=A*(369.83-X(i))^n; end resid(:,1)=Y-Ycalc; f=resid'*resid;