function P3_05B1 clear, clc, format short g, format compact xyData=[277 49000 2.3 348 68600 2.28 421 84800 2.27 223 34200 2.32 177 22900 2.36 114.8 1321 246 95.9 931 247 68.3 518 251 49.1 346 273 56 122.9 1518 39.9 54 1590 47 84.6 1521 94.2 1249 107.4 99.9 1021 186 83.1 465 414 35.9 54.8 1302]; X=xyData(:,2:end); m=size(X,1); %Determine the number of data points Y=xyData(:,1); prob_title = ([' Heat Transfer Correlation - Noninear Regression 1']); dep_var_name=['Nu ']; ind_var_name=['RE']; parm=[0.6623 0.5395 0.2454]; 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); sigmar=0; Var=0; for i=1:m Var=Var+ ((Ycalc(i)-Y(i)))^2; sigmar=sigmar+((Ycalc(i)-Y(i))/Y(i))^2; end disp([' Variance ', num2str(Var/(m-npar))]); disp([' Relative variance ', num2str(sigmar/(m-npar))]); plot(Y,Y-Ycalc,'*') % Residual plot title(['Residual Plot, ' prob_title ]) xlabel([dep_var_name '(Measured)']) ylabel('Residual') function [f,Ycalc]=NonlinFun(parm,X,Y) a=parm(1); b=parm(2); c=parm(3); for i=1:size(X,1); Ycalc(i,1)=a*X(i,1)^b*X(i,2)^c; end resid(:,1)=Y-Ycalc; f=resid'*resid;