www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregtwostage/JacobGlobalVar.m

    function X= JacobGlobalVar(TS,Xg)
%JACOBGLOBALVAR

%  Copyright 2000-2007 The MathWorks, Inc. and Ford Global Technologies, Inc.




Nf= length(TS.Global);

% Global Models
Models = TS.Global;

x= cell(Nf,1);
for i= 1:Nf
    Xgc= code(Models{i},Xg);
    x{i}=CalcJacob(Models{i},Xgc);
    m = Models{i};
    if HasTransform(m)
        yhat = yinv(m,eval(m,Xgc));
        DY= yinvdiff(m,yhat);
        % adjust rf jacobian by ytrans factor
        sdy= length(DY);
        if sdy>100
            DY= spdiags(DY(:),0,sdy,sdy);
        else
            DY= diag(DY(:));
        end
        x{i}= DY*x{i};
    end
end

X= spblkdiag(x{:});
% Augmented Data Matrix


% order is
% [F1 F2 F3 ... Fq]
% Reorder so it is 
% [S1;S2;S3 ; ... Sn];
%  New row order is [1:N:end 2:N:end ... m:N:end]

% don't want to change coeff order otherwise it is going to be
% hard to put models back together

Ns= round(size(X,1)/Nf);
if Ns>1
    Zind= reshape(1:Nf*Ns,Ns,Nf)';
    X= X(Zind(:),:);
end