%
%In an experiment, the yield z is dependent on two reactants x and y %(in mole percentage). The computed yields at 10 data points are given in a %table with (z,x,y) values given below. %It is proposed to use the following model that maximizes the yield (so as to %minimize the least square error): %z= a0+ a1x+ a2x2 + b1y+ b2y2 %Estimate the parameter vectors a,b from the data. % matlab file with least squares problem follows: z=[ 73 78 85 90 91 87 86 91 75 65]'; x=[ 20 20 30 40 40 50 50 50 60 70 ]; y=[10 10 15 22 22 27 27 27 32 40]'; n=size(y,1); A=[ones(n,1) x x.*x y y.*y]; disp('data matrix A is '); disp(num2str(A)); v=A\z; disp(['least squares solution is v=A\z ']); disp(num2str(v)); disp('verify the solution by checking the gradient: A''Av-A''z=0'); A'*A*v-A'*z %%%%%%%%%%%%%%%%%%%%%%output of file follows data matrix A is 1 20 400 10 100 1 20 400 10 100 1 30 900 15 225 1 40 1600 22 484 1 40 1600 22 484 1 50 2500 27 729 1 50 2500 27 729 1 50 2500 27 729 1 60 3600 32 1024 1 70 4900 40 1600 least squares solution is v=A\z 31.3806 3.23385 -0.0490319 -0.560854 0.043766 verify the solution by checking the gradient: A'Av-A'z=0 ans = 1.0e-09 * -0.0002 -0.0146 0 -0.0073 -0.2910 %