0001
0002
0003 function f=calib_obj(M_.Sigma_e,A,ghu1,ghx,ghu,targets,var_weights,iy,nar)
0004 global vx fold
0005
0006 oo_.gamma_y = cell(nar+1,1);
0007
0008 M_.Sigma_e=diag(M_.Sigma_e);
0009 nx = size(ghx,2);
0010 b=ghu1*M_.Sigma_e*ghu1';
0011 vx = [];
0012 if isempty(vx)
0013 vx = lyapunov_symm(A,b);
0014 else
0015 [vx,status] = bicgstab(@f_var,b(:),vx(:),1e-8,50,A,nx);
0016 if status
0017 vx = lyapunov_symm(A,b);
0018 else
0019 vx=reshape(vx,nx,nx);
0020 end
0021 end
0022 oo_.gamma_y{1} = ghx*vx*ghx'+ ghu*M_.Sigma_e*ghu';
0023 f = 0;
0024 if ~isempty(targets{1})
0025 e = targets{1}-sqrt(oo_.gamma_y{1}(iy{1}));
0026 f = e'*(var_weights{1}.*e);
0027 end
0028
0029 sy = sqrt(diag(oo_.gamma_y{1}));
0030 sy = sy *sy';
0031 if ~isempty(targets{2})
0032 e = targets{2}-oo_.gamma_y{1}(iy{2})./(sy(iy{2})+1e-10);
0033 f = f+e'*(var_weights{2}.*e);
0034 end
0035
0036 if ~isempty(targets{3})
0037 e = targets{3}-sqrt(M_.Sigma_e(iy{3}));
0038 f = f+e'*(var_weights{3}.*e);
0039 end
0040
0041
0042 if nar > 0
0043 vxy = (A*vx*ghx'+ghu1*M_.Sigma_e*ghu');
0044
0045 oo_.gamma_y{2} = ghx*vxy./(sy+1e-10);
0046 if ~isempty(targets{4})
0047 e = targets{4}-oo_.gamma_y{2}(iy{4});
0048 f = f+e'*(var_weights{4}.*e);
0049 end
0050
0051 for i=2:nar
0052 vxy = A*vxy;
0053 oo_.gamma_y{i+1} = ghx*vxy./(sy+1e-10);
0054 if ~isempty(targets{i+3})
0055 e = targets{i+3}-oo_.gamma_y{i+1}(iy{i+3});
0056 f = f+e'*(var_weights{i+3}.*e);
0057 end
0058 end
0059 end
0060 if isempty(fold) | f < 2*fold
0061 fold = f;
0062 vxold = vx;
0063 end
0064
0065
0066
0067