Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/a0asgrad.m

raw
1 function [g,badg] = a0asgrad(x,s,nobs,nvar,a0indx);
2 % Computes analytical gradient for use in csminwel.m
3 % function [g,badg] = a0asgrad(x,s,nobs,nvar,a0indx);
4 %
5 % x (parameter vector),
6 % s (diag(S1,...,Sm)): note, as in "a0lhfun", already divided by "nobs"
7 % nobs (no of obs),
8 % nvar (no of variables),
9 % a0indx (matrix indicating the free parameters in A0, and each column in A0 corresponds
10 % to an equation)
11 %
12 % Copyright (C) 1997-2012 Tao Zha
13 %
14 % This free software: you can redistribute it and/or modify
15 % it under the terms of the GNU General Public License as published by
16 % the Free Software Foundation, either version 3 of the License, or
17 % (at your option) any later version.
18 %
19 % It is distributed in the hope that it will be useful,
20 % but WITHOUT ANY WARRANTY; without even the implied warranty of
21 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 % GNU General Public License for more details.
23 %
24 % If you did not received a copy of the GNU General Public License
25 % with this software, see <http://www.gnu.org/licenses/>.
26 %
27
28 a0 = zeros(nvar);
29 %%g = zeros(nvar*nvar,1); % 4/27/97: not necessary.
30 badg = 0;
31
32 a0(a0indx) = x;
33
34 b1=-nobs*inv(a0');
35 b2 = zeros(nvar,nvar);
36 for i=1:nvar
37 b2(:,i) = nobs*s{i}*a0(:,i);
38 end
39
40 %b = -nobs*inv(a') + nobs*s*a;
41 b = b1(:)+b2(:);
42 g = b(a0indx);