% Example est ch13ex13.m % program to illustrate nonlinear model based estimatin % programmed by B. Joseph Washington University April 1993 % % This program requires the nonlinear least squares program from the % Optimization Toolbox % It also requires a function file called est82f.m which % evaluates the errors to be minimized % % First let us provide values for the measurements % Variable definitions x=zeros(10,1);xm=zeros(9,1); % Enter initial guesses for the variables to be estimated x(1)=357 ; % x(1)=t1 temperature in first tank x(2)=460 ; % x(2)=t2 temperature in second tank x(3)=20 ; % x(3)=f0 flow into first tank x(4)=20; % x(4)=f1 flow into second tank x(5)=20 ; % x(5)=f2 flow out of second tank x(6)=60 ; % x(6)=c0 concentration of feed into first tank x(7)=20; % x(7)=v1 volume of first tank x(8)=10 ; % x(8)=v2 volume of second tank x(9)=30 ; % x(9)=c1 concentration in first tank x(10)=10; % x(10)=c2 concentration in second tank % Now enter the measurements on the process % These are stored in xm and passed to the function that % evaluated the residuals xm(1)=350.; % measured value of t1 deg R xm(2)=450 ; % measured value of t2 deg R xm(3)=20.5; % measured value of f0 cuft/hr xm(4)=20.; % measured value of f1 cuft/hr xm(5)=20.1; % measured value of f2 cuft/hr xm(6)=60.1; % measured value of c0 lbmol/cuft xm(7)=20.5; % measured value of v1 cuft xm(8)=10.1; % measured value of v2 cuft xm(9)=30.1; % measured value of c1 lbmol/cuft options=[];grad=[];% We are not going to use these options hence set to null % The following call solves the nonlinear least squares problem % The call requires the Optimization Toolbox xr=leastsq('ch13ex13a',x,options,grad,xm); f=ch13ex13a(x,xm); fr=ch13ex13a(xr,xm); [x xr] pause % hit any key [f fr] norm(x-xr)^2