function P3_03B2 clear, clc, format short g, format compact xyData=[231.07 1.14E-02 240 1.21E-02 260 1.39E-02 280 1.59E-02 300 1.80E-02 320 2.02E-02 340 2.26E-02 360 2.52E-02 380 2.78E-02 400 3.06E-02 420 3.34E-02 440 3.63E-02 460 3.93E-02 480 4.24E-02 500 4.55E-02 520 4.87E-02 540 5.20E-02 560 5.53E-02 580 5.86E-02 600 6.19E-02]; X=xyData(:,1); m=size(X,1); %Determine the number of data points Y=xyData(:,2); prob_title = ([' Thermal Conductivity of Gaseous Propane']); dep_var_name=['Thermal Conductivity (W/m*K) ']; ind_var_name=['Temperature (K)']; parm=[0.001 1.8]; 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) c=parm(1); n=parm(2); for i=1:size(X,1); Ycalc(i,1)=c*X(i)^n; end resid(:,1)=Y-Ycalc; f=resid'*resid;