设为首页收藏本站|繁體中文 快速切换版块

 找回密码
 立即加入
搜索
查看: 8532|回复: 4

时间序列达人们来讨论一下matlab中predict函数

[复制链接]
  • TA的每日心情
    开心
    2016-2-29 16:07
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    累计签到:1 天
    连续签到:1 天
    发表于 2010-9-28 11:13:27 | 显示全部楼层 |阅读模式

    马上加入,结交更多好友,共享更多资料,让你轻松玩转电力研学社区!

    您需要 登录 才可以下载或查看,没有账号?立即加入

    ×
    打开程序也看不懂,600多行代码,请达人们帮助解读一下,先谢谢各位仁兄了~~
    "真诚赞赏,手留余香"
    还没有人打赏,支持一下
    楼主热帖
    帖文化:【文明发帖 和谐互动】 社区精神:【创新、交流、互助、共享】

    该用户从未签到

    尚未签到

    发表于 2010-9-28 12:40:43 | 显示全部楼层
    贴代码上来哇
    "真诚赞赏,手留余香"
    还没有人打赏,支持一下
    帖文化:【文明发帖 和谐互动】 社区精神:【创新、交流、互助、共享】

    该用户从未签到

    尚未签到

    发表于 2010-9-28 13:03:22 | 显示全部楼层
    你想自己编一个predict函数?
    "真诚赞赏,手留余香"
    还没有人打赏,支持一下
    帖文化:【文明发帖 和谐互动】 社区精神:【创新、交流、互助、共享】

    该用户从未签到

    尚未签到

    发表于 2010-9-28 17:53:25 | 显示全部楼层
    恩,贴代码上来大家看看
    "真诚赞赏,手留余香"
    还没有人打赏,支持一下
    帖文化:【文明发帖 和谐互动】 社区精神:【创新、交流、互助、共享】
  • TA的每日心情
    开心
    2016-2-29 16:07
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    累计签到:1 天
    连续签到:1 天
     楼主| 发表于 2010-10-1 20:42:36 | 显示全部楼层
    回复 4# climber " e0 X) i2 }5 K) \; H; w7 U! n

    4 l4 }. ?% G& Y, r  K7 B
    / `" a' u' B2 X' p! |3 [    谢谢大家的关注~~
    $ u8 ^+ ?/ e* x! @' z& q) Qfunction [yhat,xi,thpred]=predict(varargin)
    4 [5 a/ E1 Q* A% q9 z/ v/ h/ L%PREDICT Computes the k-step ahead prediction.
    ' @" `. _! x. Y: a%   YP = PREDICT(MODEL,DATA,K)7 V2 H' u! Y3 M0 I8 z
    %
    9 V6 t# {$ C* n: t7 E# ]%   DATA: The output - input data as an IDDATA object, for which the1 F4 a. e5 Z* ^8 [
    %   prediction is computed.; C3 o6 g' t3 |5 M6 F' W- z1 a
    %
    # Z3 H8 O( t0 ]( h%   MODEL: The model as any IDMODEL object, IDPOLY, IDSS, IDARX or IDGREY.* g9 d, v3 b% N7 F8 y6 ~" E) J
    %/ O9 k. C  a/ u, ~/ d$ t
    %   K: The prediction horizon. Old outputs up to time t-K are used to
    " Q$ x% C4 K3 ~%       predict the output at time t. All relevant inputs are used.
    7 h1 X# w/ P4 H- k# A+ [" w4 o%       K = Inf gives a pure simulation of the system.(Default K=1).
    & z* r% F' F' `( g8 b2 \# I5 m4 c%   YP: The resulting predicted output as an IDDATA object. If DATA
    + ~, J8 R1 ^) N' a%       contains multiple experiments, so will YP.; s0 L! |* X1 J+ X! A
    %
    / R- I9 Q% k* g  D%   YP = PREDICT(MODEL,DATA,K,INIT)  or
    5 s4 K+ z: O) f! R; t' v0 x%   YP = PREDICT(MODEL,DATA,K,'InitialState',INIT) allows the choice of
    . G9 F4 W. P7 F' `; f* a%   initial state vector:
    # c1 J, V& _$ L! f, ~( s& q- {%   INIT: The initialization strategy: one of1 R, v' V( F( ]6 }& |- W, @% z
    %      'e': Estimate initial state so that the norm of the
    & ~! S! L4 u9 P( C%           prediction errors is minimized.
    : r7 i. U6 c; Q7 d6 Q# i%           This state is returned as X0e, see below. For multiexperiment
    % r8 E3 v8 |: S  P3 v1 p%           DATA, X0e is a matrix whose columns contain the initial states
    3 e! z% s  g5 k- C7 R, h%           for each experiment.
    # k4 a* c6 M/ b0 j  B+ u( W2 u- z! c%      'z': Take the initial state as zero
    2 n7 c9 y0 f' ]" x* M( I! N%      'm': Use the model's internal initial state.
    . F: U$ w* z& n%      'd': Same as 'e', but if Model.InputDelay is non-zero, these delays
    6 I  A" [8 o* d- ^%            are first converted to explicit model delays, so that the are) \9 D$ K* n7 F  ~
    %            contained in X0 for the calculation of YP.
    7 p/ i9 J- M/ _9 m; x% Q%       X0: a column vector of appropriate length to be used as initial value.! P8 S4 S, m  `% T! Q
    %           For multiexperiment DATA, X0 may be a matrix whose columns give6 u& Q/ T7 [1 \6 p( x
    %           different initial states for each experiment.
    7 W& ~# d* E, F) z; v$ U6 R%   If INIT is not specified, Model.InitialState is used, so that
    * r  L# s: {1 R; |% h%      'Estimate', 'Backcast' and 'Auto' gives an estimated initial state,
    " M, x' N, C5 Z3 Y1 N" Y%      while 'Zero' gives 'z' and 'Fixed' gives 'm'. If Model is an IDARX
    : t/ }$ j- J6 \+ L8 ]%      model the default initial state is 'z'.& p8 B, p3 x9 r9 A0 O5 A9 ~
    %
    ( {# \0 m' U4 V& |; O" D- r%   With [YP,X0e,MPRED] = PREDICT(MODEL,DATA,K) the initial state(s) and the6 C9 m1 A( D  E% r& b
    %   predictor MPRED are returned.  Note that if MODEL is continuous time, X0e8 H2 T' u/ ~+ C
    %   is returned as the states of this model. These may differ from the initial
    $ i8 O% a* G) S3 D%   states of the discrete time model that has the sampling interval(s) of
    $ x! Z5 i  g3 m2 s) O4 q+ F* F! v6 E%   DATA. Also when INIT = 'd' only the states of MODEL are returned in0 {1 `& C  T1 U! |; M# B
    %   X0e. (To obtain the full X0, apply first INPD2NK to a discrete time# L( w6 _& ~: r8 v6 D" ~0 E) m
    %   version of the model.)
    ) {0 n& D9 b5 p- I%   MPRED is a cell array of IDPOLY objects,/ ?' }/ Z& H' N9 @) W" i
    %   such that MPRED{ky} is the predictor for the ky:th output. The matching$ Q4 h2 C, n2 l5 H8 K7 Z* w7 S
    %   the channels of MPRED with data follows from its InputNames.* Y. e4 z( u$ g
    %   See also COMPARE and IDMODEL/SIM.# u6 s- f% u8 f: W" T
    %   L. Ljung 10-1-89,9-9-94( J/ P2 p# O) l  F* S
    %   Copyright 1986-2008 The MathWorks, Inc.
    4 n5 B+ }' H% h/ q; e/ S%   $Revision: 1.1.8.9.2.1 $  $Date: 2008/08/01 15:32:39 $1 F: ^  W" `- E& G
    / x2 H6 T4 z/ W/ R/ v; E8 e
    % First find if there is any pair 'InitialState', init in the argument
    3 t2 J9 o8 w' e& r6 }% list:( S" p% l/ a- M0 a, K
    nr = find(strncmpi(varargin,'in',2));' B  d- ]: p& b+ k- ?
    init =[]; xi = [];# \+ V: g7 t* v" ?
    if ~isempty(nr)9 Z5 j0 E7 Z6 V/ G
        if length(varargin)<nr+1
    " s$ C; ~4 ^" r6 u1 }        error('Ident:general:optionsValuePair',...
    / Q9 R; P. F1 F+ R$ N8 U* X                'The "%s" option of the "%s" command must be specified using a name/value pair. Type "help %s" for more information.',...
    $ B4 ?/ g$ h/ p  B) N, C$ e                'InitialState','predict','predict')3 Q8 h6 P# Y' H
        end* I2 S' j  A1 {' m' w
        init = varargin{nr+1};
    ! x7 p; t6 \- e! I+ Y) P    if ~isa(init,'char') && ~isa(init,'double')
    + o5 {# x. q) v2 h6 R, X        error('Ident:analysis:IniSpec2',...
    ) u$ i$ t0 }$ k) }# w9 E" O            'The "InitialState" option of the "%s" command must be set to a valid character or a vector/matrix. Type "help %s" for more information.','predict','predict'). s, P& K& j0 q( d* ?; Z
        end
    + m9 h1 w) Y9 K, C, R0 S    varargin(nr:nr+1)=[];%
    ! [! y+ D% Z" H9 k: ~1 nend
    7 L" g' z8 `7 Zif length(varargin)<2
    ) ]( E9 q/ e7 s9 B  W    disp('Usage: YP = PREDICT(MODEL,DATA)')
    0 h! y7 L! C  k  A( M: q    disp('       YP = PREDICT(MODEL,DATA,M)')
    2 ?& }5 Q- o) V+ w    yhat = []; xi=[];: V6 w' p6 W6 i7 o. _
        return' g) a+ g$ P6 Q9 Z5 T
    end
    4 X2 f8 o! C. fdata = varargin{1};" `2 X/ s9 ~( N- B! A0 J! H! k
    theta = varargin{2};9 l1 q; O, A; o7 }8 @  t' k/ G: b- [  F
    if length(varargin)>2) p1 ?1 d7 q  j# F# c. c  X9 J
        m = varargin{3};, e3 b* {, _# ~9 m% V
        if ~isnumeric(m) || ~isscalar(m) || ~isreal(m) || round(m)~=m || m<1
    + P( u7 M0 Y8 u$ z        error('Ident:analysis:predictInvalidHorizon',.../ y0 G3 \6 e+ w$ H
                'In the "predict(MODEL,DATA,K)" command, the prediction horizon K must be a positive integer.')
    2 w) P2 b0 J0 `  W    end   
    - n$ P6 U4 R5 {+ Q0 jelse
    + v0 Z' e* d: K9 j4 r& `    m = 1;
    - {0 d; }, E3 nend, e- ]1 `9 ~5 U, e6 g
    if length(varargin)>3 && isempty(init), r+ ?( d' H/ n  U/ S- x
        init = varargin{4};% a! c' J% W8 [
    end" z* {. m' z, a2 {/ X9 s" h- h
    thpred = [];) ^9 {% H4 W( L9 z
    yhat = [];
    8 ?1 v9 O% k. C+ Fif isa(data,'idmodel') % Forgive order5 T3 b2 W9 f* D
        data1 = theta;& _4 \2 u3 y4 b6 T
        theta = data;
    0 l1 [' S% ^5 }) o) J7 F! Z; d/ w    data = data1;) `9 P. y. Y1 q  T+ k) R
    end& @% O& y* d, H5 ?. a
    nxorig = length(ssdata(theta));
    % R% k5 G8 Y" c& e[nym,num] = size(theta);
    3 F" G! K! G2 H& ^# S/ N) aif isa(data,'frd') || isa(data,'idfrd')
    9 _* O& }$ v: t7 I    error('Ident:analysis:predictIDFRD',...+ A. q+ t; u9 ?" }0 V$ A: m
            'The "predict" command is not applicable to frequency response data (IDFRD object).')) [' A+ I. x' g' C4 L- B
    end
    ; h+ n8 m, x0 t% w: b; K# T! kif isa(data,'iddata')7 }1 Y% M2 f2 ~( q9 C
        [Ncap,ny,nu] = size(data);% y' V7 j9 H/ G, I' E4 I) H
        if ny~=nym || nu~=num
    1 v7 \0 V+ ?4 D0 C        error('Ident:general:modelDataDimMismatch',...$ {6 g3 r1 J4 B$ ?: O
                'The number of inputs and outputs of the model must match that of the data.')
    ) X5 }3 p0 b/ M6 ]. ~3 }2 O    end
    0 [6 _1 j% C5 s4 ^9 T, B6 ~5 gend7 {$ }2 ]- w8 w/ w4 I
    if isempty(m), m=1; end
    ; N) p( `0 r, Cif ~isinf(m),
    - a% n% [8 w/ C5 k# H  v    if m<1 || m~=floor(m)
    2 W+ @. B7 d; v: g) I  Q        error('Ident:analysis:predictInvalidHorizon',...
      b' R6 p2 o  u6 {: n/ V$ i            'In the "predict(MODEL,DATA,K)" command, the prediction horizon K must be a positive integer.')( v8 g+ L) M" G6 ]
        end
    ) _. w7 ^8 H! p2 Fend
    , O$ C; b: L1 ^7 q$ y" J% First deal with the special case of continuous time data and continuous$ J+ L; _8 z1 [
    % model:2 J& ?8 m2 |1 j( }- G
    if isa(data,'iddata') && any(cell2mat(pvget(data,'Ts'))==0)
    ' x$ F* F9 q9 I% n    if ~isinf(m)! c, R' T( i. R
            error('Ident:analysis:predictCTData',...7 H& }9 @: a$ h% o; H
                'The "predict" command cannot be used with continuous time data.')
    ! E" s% T% K9 `  K    end
    0 p8 @8 J; Y5 B% |" G3 m/ P% m    yhat = sim(data,theta);%没懂
      S' L6 `% q/ M) T; Y4 j    if nargout == 0$ {) t' U3 S  F" y, d: E' v
            utidplot(theta,yhat,'Simulated')
    0 o' o$ w* g+ g6 Q. N3 [+ V8 j        clear yhat+ n8 M+ _( i. m. o9 p. _' g
        end( f' j3 X, B  K" z
        return
    7 {) W% h; h" I6 V; F2 b8 oend
    " s: p( r$ m7 C& ^" }if isempty(init): y9 b' Q* ]- y5 A. t1 X# W
        if isa(theta,'idarx')
    - C- l; x6 w. s' u1 d        init='z';
    + ^8 j& S* Y+ Y1 J    else
    ! N& K/ p4 ~: W$ l! X4 [+ \        init=pvget(theta,'InitialState');8 d" s1 [8 v& F% z
        end* E' A2 `+ O5 H" M0 d. l
        init=lower(init(1));
    & @0 ?* e/ N; y5 A2 K. N) ^    if init=='d'; M' a8 G. |* X9 e% M
            inpd= pvget(theta,'InputDelay');# u0 ~1 n+ ]2 w" ?% n
            if norm(inpd)==0
    $ N! y' y& U/ l# j. h$ K            init = 'e';% N& q7 [4 p2 y( T) R+ A
            end
    " |: K7 L0 D1 F9 A' t0 k    end
    ( D- ~6 ?" ?6 D8 i6 a0 }    if init=='a' || init=='b'' ?. O) _& d/ d1 h! _
            init = 'e';
    , l! a# p* S/ H9 X    elseif init=='f'
    ! I( N% i5 u1 i; S+ W        init = 'm';+ n2 }, _! x& y9 t9 M( ?* l
        end. J. X6 {' d2 T% i; c( G2 B
    elseif ischar(init)* z1 O5 z# F, B$ {8 `! `# d5 B
        init=lower(init(1));
    + c3 O% O; t2 @) J$ |    if ~any(strcmp(init,{'m','z','e','d'}))
    3 ~8 ~* |8 Z5 D: I4 L6 e        error('Ident:analysis:predictIni3',...
    3 {$ a8 X9 Q. E' M            'The "InitialState" option of the "idmodel/predict" command must be set to ''E(stimate)'', ''Z(ero)'', ''M(odel)'', ''D(elayconvert)'', or a vector.')
    % M( K) t, A: H' E2 f    end
    , k, g6 a7 I/ f9 J  w    if init=='m' && isa(theta,'idpoly')
    ' U" V5 w3 m/ N; f        warning('Ident:analysis:predictIni4',...' x: o3 A% }8 L+ [7 X' A6 d
                'Setting the "InitialState" option to ''m'' in the "predict" command is same as setting it to ''zero'' for IDPOLY models.')
    ; h. j" f" f6 R# }( i/ ?6 ?7 J    end6 D/ n  H$ {' Z  ^0 \! m, i
    end2 M3 o5 D4 a9 w5 b
    %% Now init is either a vector or the values 'e', 'm', 'z' 'd'- C0 N' ?' u5 p3 v
    if isa(data,'iddata');
    6 M1 W$ D% r1 o    if strcmp(pvget(data,'Domain'),'Frequency')9 h! Y  F( P4 J8 Z) [
            if m<inf
    & Q8 Z7 Q' w6 \+ p) w7 T* x            error('Ident:analysis:predictFreqDataFiniteK',...
    + d& J" Z8 R+ k0 U                'Prediction with finite horizon is not applicable to frequency domain data.')
    7 M; d3 Y' Q/ I# a, W8 g        end
    0 m' X4 _! j: j6 G/ Q9 Y( e8 t    end# e2 X) J: f* c' F
    end3 g, o3 r7 P; Y  J7 j
    if isa(data,'iddata')
    , t( t2 O9 O# L% ~    [uni,Tsd,inters] = dunique(data);
    7 ^( B- Y, w" r* }    iddflag = 1;
    ( \/ {8 Q. I1 ?+ ^else
    6 K# @4 F' @& z$ q    iddflag = 0;8 Z1 C5 F* C. q( i: j( S
        uni = 1;
      ?3 ?4 x: v- e/ l' z- W, B& Y/ e    Tsd = 1;
    % a3 {/ ?0 c* d6 e( M, k    inters = 'z';3 @1 z" O4 J9 @! s/ r3 x- ~
    end# r; y+ @5 s: h; t* A' n: o: u/ h
    %% Do away with continuous time right away:$ H. F# {) W. M4 S4 o8 y$ \
    Ts = pvget(theta,'Ts');+ p3 `  {; ]' w# v) ~0 x/ f8 r
    if Ts == 0
    % d" M  @# l1 f1 `4 k    theta = pvset(theta,'CovarianceMatrix',[]); % Less calculations
    4 g* n; F* Z8 h. S% f( P    ms = idss(theta);4 Q6 S* T$ E8 |; f
        nc = size(ms,'nx');& ^6 B1 P$ T6 a% F$ ~
        if ischar(init)* _2 ]7 H& H. {/ \9 ~
            if init=='m';
    + O8 ~) p; ~" N2 @- Y            init=pvget(ms,'X0');+ e7 K& `8 I# a$ O. Q4 N
            end( |& ^2 Y) p5 S% @" d+ l0 l4 m
            if init=='z': l8 t7 F" c; F/ b- C# b. p, }! Q
                init=zeros(nc,1);
    / F; j' B$ I5 v$ Y        end  c1 Z! I6 I' i4 r  U
        end
    - ~& E2 {4 t: l/ K! h! r    if ~isa(data,'iddata')/ n" D5 m: ~: h! }- j0 x1 y
            error('Ident:analysis:predictDataFormat',...1 s, Y# m  `; @4 Z
                ['For a continuous time model, data must be specified using an IDDATA object.',...
    / ^9 b% b3 R; B            'Type "help iddata" for information on how to create the IDDATA object.'])
    ! Q0 v" F' q5 A& `! ^    end
    1 _* Q( B) Q2 Z3 D3 F) o    Nex = size(data,'Ne');, @$ Z0 U" I, q% A' H1 d) U
        u = pvget(data,'InputData');' g/ I/ B; k- k1 O
        u1 = [];: z/ G0 T, }, m
        for kexp = 1:length(u);
    ! o  h2 D. f9 T: |6 W- f        u1 = [u1,u{kexp}(1,:).'];' S  b' y! u3 B. w/ A4 _
        end- H3 z) a7 ^0 C0 {/ O
        nu = size(data,'nu');
    , G$ F: ?  s; c    if uni
    * u# {; F  {/ ~( a; I$ I! e) f% ]        nc = size(ms,'Nx');9 h. j3 W( D: J1 p4 Z
            [md,Gll] = c2d(ms,Tsd,inters);
    ) V3 `( m/ x, m* J" ~5 }2 K        if init=='d', md = inpd2nk(md); init='e';end4 ^! w% O4 r5 b
            % First work on init
    8 |8 Z5 q1 ?0 L% K        if isa(init,'double'). ~0 r: }- S4 F* E6 m9 i
                [nxi,mexp]=size(init);) ^2 z, ?5 V2 B) m8 _0 `
                if nxi~=nc0 h' }* q- B+ q* ~2 u" O
                    error('Ident:analysis:IniRows',...
    " K" @3 Q- ~+ m8 m. u: i8 F+ q                    'The value of the "InitialState" option should have %d row(s).',nc)  ^- X* W5 u4 F& \& B7 i
                end+ u5 r# I; r, _7 v
                if mexp==1 && Nex>1% v( z! \+ B  T/ \/ @2 k+ N/ O
                    init = init*ones(1,Nex);
    : j! ~, v" y) k( i* q! F% w                mexp = Nex;
    $ W+ J& `3 _, x" S; O            end: ?" T$ ]* U; @" k& e8 d' u
                if mexp~=Nex
    . R# O3 L& |& r% c1 m                error('Ident:analysis:IniSize',...
    $ ?8 |- }3 p: K, n( m                    'The "InitialState" option value must have either 1 or Ne columns, where Ne = no. of data experiments.');
    ) T, G0 M9 v2 N9 W, S' y9 `            end" x1 n% \) k, v& s/ f8 G7 V
                if ~isempty(Gll)
    * J4 R9 }4 ~. x; e/ @) k& q                init = Gll*[init;u1];1 r' @' U) z8 q' \
                end
    # Y! r1 M+ A. [; T        end. ]3 N$ m& e% c* h$ C8 H" e
            if init == 'e'# ]$ L0 S* r  Z
                inite = x0iniest(md,data);
    5 ]; |1 I! D/ l. m4 m        else; @* z' H3 ?0 [3 t8 V
                inite = init;
    : o6 ~$ P# s) e5 H        end  w( d; [, R+ M* |
            yhat = predict(md,data,m,inite); %Check XIC!. u2 ]- h0 v- C% Z# O5 O& i
            if ~isempty(Gll)6 Q* K4 |- g0 M* o
                xi = inite(1:nc,:)-Gll(1:nc,nc+1:nc+nu)*u1;
    7 q- H8 g. z! V$ x$ n; W- ^# ~4 Q        else
      a! P1 ]0 M! @& T            xi = inite(1:nc,:);( m$ a7 F+ [9 o2 W/ I4 _
            end  J& {- W1 d; _2 a2 i/ w
        else % Different sampling intervals
    % i' ^/ f& f9 E: O  ~( L/ g        Tsd = pvget(data,'Ts');0 O5 A# b6 |  y! G$ N. d: w- r
            ints = pvget(data,'InterSample');5 [' W2 t9 O+ F
            %xic=zeros(nc,Nex);
    % _1 ~* T, L4 d0 o' U  ?        for kexp = 1:Nex
    0 f0 o4 Y; }) E: z$ ^5 h: ]            [md,Gll] = c2d(theta,Tsd{kexp},ints{1,kexp});
    7 C0 P+ o* p: m$ [* B4 X% T; O            if init == 'd', md = inpd2nk(md); init = 'e';end
    9 N. z' B: H0 i- J- I. r! i( C0 I9 A/ M            if isa(init,'double'): {! f2 n0 i/ G& H$ ~, \" B
                    if ~isempty(Gll)$ ~7 ^" [4 U: ?
                        if size(init,2)==1
    ( d) g/ d- G$ O' P2 ]2 }                        initk = Gll*[init;u1(:,kexp)];
    ( r4 ~  {0 A% h9 d1 v* ^5 v% e                    else: H) ~, ]% L$ V8 ]0 I' d: r8 M  j; p, {
                            if size(init,2)~=Nex+ a* y2 H1 V9 l1 R* E+ H) ?
                                error('Ident:analysis:IniSize',...5 H5 c9 W2 H0 q) K, u# P
                                    'The "InitialState" option value must have either 1 or Ne columns, where Ne = no. of data experiments.');; Q5 n0 j% g; X5 X
                            end
    & {0 {+ |- Z+ }; A% K6 D0 _                        initk = Gll*[init(:,kexp);u1(:,kexp)];9 T* k9 R# ?! I- k. R8 C
                        end, j3 z% r( W2 z
                    end3 C; \: ^# z4 a% a. [* S$ Z
                else$ T& {  y' [6 Y
                    initk = init;
    6 [% T- _; l; c1 r6 Y            end' L2 _2 K8 ]* D/ e  O4 D4 w; K
                if init == 'e'2 K% f4 ?+ H* N7 \& }0 o
                    initk = x0iniest(md,getexp(data,kexp));
    - B1 c/ y3 L5 T' Z            end: ?4 L* o& B, X' Z
                if ~isempty(Gll)
    # N2 |2 j) l6 T8 o/ e# ]1 w% j$ |, C                xi(:,kexp) = initk(1:nc)-Gll(1:nc,nc+1:nc+nu)*u1(:,kexp);& V' X: y% Y: Q8 n
                else
      F* Q- b( k0 `                xi(:,kexp) = initk(1:nc);
    ) q, I! ]1 f4 E* \7 N7 ^            end
    6 Y* C) c9 H! D" h            yhatk = predict(md,getexp(data,kexp),m,initk);
    : v  f$ @& ~0 G+ p3 G8 b* p/ x            if isempty(yhat)
    1 g8 l! R' J) F# |* W                yhat = yhatk;5 ^8 a* [6 I: a) f
                else) [8 f- m$ n- \, w" d+ B
                    yhat=merge(yhat,yhatk);
    / Z8 j* A3 K% R! [' t* Y            end1 d6 B* M1 b+ m2 I
            end
    4 a( k5 c: o8 p0 N0 f# V2 V( q    end
    6 t: i+ q3 ]1 ]    if nargout == 0
    : C0 s5 o! C1 B" X; O/ j9 _        utidplot(md,yhat,'Predicted')( q& j& ~( e# d8 a8 \1 Z) U6 v: U2 f
            clear yhat
    ) U5 G( i: s% F    end$ v- U* T% G" M. e- A7 M4 a; ]+ [
        return
    2 F( n  b* v5 C6 S/ Welse %Ts>0/ Q. r  w  b/ q- C, P8 ]% A
        if init=='d'
    1 Q5 v; z/ c' k7 Y( }5 O" h- Z        if any(pvget(theta,'InputDelay')>0)7 b' }% @1 j7 Z% J  E. M# s4 L- y
                theta = inpd2nk(theta);
    ! s4 X& X) ?& e7 z9 A        end
    * r% T8 [* l0 h& Q$ k$ K; c2 K6 C4 B0 a        init = 'e';
    1 [& h* L; R" F6 T8 s8 o    end8 g" D* O/ k8 k0 Y6 |* N
    end8 y/ R8 V- Y) h$ y; l$ |$ h
    if isinf(m). g0 p! D3 Q/ E* g9 |' z
        if ischar(init) && init=='e'
      T: d/ a4 w; C  x( \2 l7 R        X0 = x0iniest(theta,data);
    5 _* {* L# |' m' u' C/ [        init = X0;  % Note the difference with COMPARE, which fits
    " F) k! [9 x6 C& q& E6 s        % X0 with K = 0;- c: l3 c( t' N+ q% h1 G3 {5 `
        end  T6 }& ]9 O: P: F7 D: d; L
        if ~isa(data,'iddata')
    5 N. O7 S; y/ U& w) X        data = data(:,nym+1:end);6 l- Z& H' {" ]3 `" J$ t
        end
    - p$ Q/ I9 [5 i' c1 K0 N    [lw0,id0] = lastwarn; was = warning('off','Ident:analysis:unstableSim');
    0 F1 C) F5 G8 t9 g9 I; o0 y    try$ O1 w+ R5 O/ Q+ V( e8 v
            yhat = sim(theta,data,init);
    4 B/ C8 q6 S  ]) U    catch E
    $ e3 }( l+ D% C+ x: m6 `        warning(was)
    ! M, L3 m5 A, ]+ G( v0 X        lastwarn(lw0,id0);
    + {$ r$ v8 F1 B4 C6 @. `: n. M        throw(E)
    ; h4 w  Y( b8 t+ A& M0 O    end% ~( }% Q5 w/ _5 q2 E0 `
        warning(was)( ?( n' ]' q3 C# g" s: }
        lastwarn(lw0,id0);
    2 e# }  T- t+ b8 k    0 d$ K% w" d; B* {" s
        thpred = theta;# |8 o9 q+ k$ ~* P" f
        if nargout == 0% x" J, b6 |, K+ B
            utidplot(theta,yhat,'Predicted')
      x4 w% L+ ?9 L5 c0 ]: I+ E        clear yhat
    3 u1 V- m; ^+ \  ~# a8 v. W# f6 _  ^    elseif nargout>1* k" {1 \0 X7 t( c
            xi = init;3 h5 s2 f" f+ c* g8 v7 J
        end8 K1 o; T% {, S2 t/ ?( \2 E: P- H# @
        return* A% o9 p& U) [6 Q& p) S8 C# S
    end
    & C* l/ L/ W/ |9 i%Inpd = pvget(theta,'InputDelay');: G' ^6 s4 V1 L; U( d+ V
    nu = size(theta,'nu');6 d  h2 p2 B$ D; v( B6 E0 C
    if ~uni# B  l; f: Q) k
        Tsd = pvget(data,'Ts'); Tsd = Tsd{1};
    : f% `; p. k7 r8 ~. g) s    warning('Ident:estimation:nonUniqueDataTs',...7 p. p+ h' h" E: u: l
            ['The data set contains experiments with different sampling intervals.\n',...
    ! b- |5 B2 f6 R& {% c$ p* C        'Sampling interval from the first experiment (=%g) will be used.'],Tsd)3 G8 A3 W  d+ p, y; k  \+ r$ P% n
    end
    6 ?6 j$ w# q4 \( Q6 Qif iddflag && any(abs(Ts-Tsd)>1e4*eps)
    * ^  K2 X& `# R4 _; I    warning('Ident:analysis:dataModelTsMismatch',...( x5 f# {$ y9 [  d# q: Q- ?
                'The data and model sampling intervals are different. The data sampling interval will be used.'), B+ a. l7 P6 S- Q+ v0 m
    end, r- [2 e. Z+ \: q/ K
    Inpd = pvget(theta,'InputDelay');, |' b3 p. m- r% N- g3 [
    if init=='d'
    : w. a1 P4 e$ U' C" B* j3 R    init = 'e';' _2 u' d" P( P- E0 z. r
        theta = inpd2nk(theta);! {2 |5 q4 n" X+ k7 u
        Inpd = zeros(size(Inpd));3 v! b. S% j8 V, J/ M
    end
    " e) \7 G+ Q1 O* g. ~! Yif isa(data,'iddata')
    . O. f' N; w% D    if isnan(data)
    8 d( g; F! t) f* i# |6 C        error('Ident:general:idprepMissingData',...
    % V" }, o& j8 W6 O            'Data contains NaNs which represent missing values. Use the "misdata" command to fill in the missing values before using.');
    0 w1 ~& v0 }2 Q& N# P    end
    ' F- _5 c# `+ c# Z& ~$ w    data = nkshift(data,Inpd,'append');/ q& ^/ M' ~, _; J, r) Q* J) W
        theta = pvset(theta,'InputDelay',zeros(nu,1));: G" M- V; A8 l! I
        [ze,Ne,ny,nu,Ts,Name,Ncaps,errflag] = idprep(data,0,'dummy');6 S, a- ~+ J# d- U: o
        %if ~isempty(errflag.message), error(errflag), end
    7 y, ?) @3 v( {2 s  [: w    if ~isempty(Name), data.Name = Name; end, g. C4 N4 ^2 M' l% @
        iddatflag = 1;( G2 E% S8 J  g
    else9 w2 l, H% ^2 k( ^1 [7 }
        if norm(Inpd)>eps
    / F. O& `+ v7 F. x5 f8 s        if iscell(data)  7 Z3 p9 T4 }8 P7 x- v( u: s) t* G* t
                data = data{1};4 I+ J, B  r; i2 I  O! c% L
            end
    $ B5 |; o( l& `        [Ncap,nudum] = size(data);
    $ F" @. {1 z; Z7 ]' i' K        nk1 = Inpd;; ]3 C* Y  @$ S3 E7 R& Z8 w
            ny = nudum - length(nk1);
    3 u2 v7 f) r5 \: U+ l        Ncc = min([Ncap,Ncap+min(nk1)]);
    : x$ }7 Q2 l) s6 [        for ku = 1:length(nk1)
    ' t8 a' a! u$ m3 w2 [( V: J+ S            u1 = data(max([nk1(:);0])-nk1(ku)+1:Ncc-nk1(ku),ny+ku);& p+ U8 f. V8 V3 w7 C# o2 ?
                newsamp = Ncap-length(u1);6 k% d0 ~; w) m7 ~
                if nk1(ku)>0; h5 g6 L, h2 \  X; \
                    u1= [zeros(newsamp,1);u1];6 c# |$ z- x1 ?. m. r0 }, f  Y1 ?- Z- C
                else8 Z" j( V  ]2 z/ {  n
                    u1 = [u1;zeros(newsamp,1)];9 H* g8 x4 W7 L, Z
                end
      x4 v7 `0 V- F            data(:,ny+ku) = u1;/ A2 p2 x* X6 ]; _+ e; X  I( @
            end
    # P. D3 y2 P: V$ s4 i8 v: h; c    end# r% m) @" K3 r
        iddatflag= 0;: y0 C: O7 o( A
        if ~iscell(data), ze ={data};else ze = data;end
    4 {5 s  g5 d8 z7 B8 @    Ne = length(ze);4 n5 D1 q7 d+ |1 J
        nz = size(ze{1},2);1 x1 F; i# C' g( V& e! {: Z
        for kexp = 1:Ne
    " G0 a# P# U+ w3 Y6 G" Q+ f3 N        Ncaps(kexp) = size(ze{kexp},1);- m4 w, N/ ?6 {8 H& ~! ]5 m+ Y- F
        end% v! v  j7 o0 O& j% J8 R5 ]6 K- d
        %Ts =[];
    ! k" a. T/ ^" |: F3 h' Lend. U& _" U/ ~# n
    if m>=min(Ncaps)" _& H) G. Y1 q# Y5 U1 `
        error('Ident:analysis:predictLargeK',..., @) A" [5 y  j% b4 a0 {" c
            'Prediction horizon must be smaller than the number of data samples.')# y6 R! @! ?( U% T* a; J! n- {/ P
    end* J! y: \) ~: I2 g: v
    [A,B,C,D,K,X0]=ssdata(theta);" \# r; V! c* S0 k) |' m4 t! o7 i
    [nyt,nx]=size(C);nut=size(B,2);  g0 _# M- C% I1 C% p8 r
    if iddatflag' o$ O. ^* g" Z: D3 m# u- k8 @
        if ny~=nyt || nu~=nut' X! R, O5 |+ B6 H
            error('Ident:general:modelDataDimMismatch',...6 j# p$ w& P- ~" Y- }+ I, B; s
                'The number of inputs and outputs of the model must match that of the data.')
    % L" S, p" g( P$ O& W. K# `: W    end
    " C3 I% G) o% ?' ?+ l: |$ o" Yelse
    - e7 q* h: W0 [) _3 b7 K    if nz~=nyt+nut
    ! x2 A: }7 R/ n% H/ q        error('Ident:general:modelDataDimMismatch',...
    1 p2 `% b4 W0 y: v$ O            'The number of inputs and outputs of the model must match that of the data.')5 ]4 Q$ S; Z) P" O& N, U# j
        end6 ]( X' }, I+ v4 o% l, v
        ny = nyt; nu = nut;
    & f# c. N$ @: t9 q: pend, x9 d; P. a+ z# }( I3 E# P1 o
    if strcmp(init,'e')- G4 K4 Q" P1 R0 ^
        X0 = x0iniest(theta,ze);
    , Y+ r6 Q% F& f% e+ n! S; d! [) Felseif strcmp(init,'z')
    $ W+ f7 i# ]# S. R8 I4 |2 U8 P    X0 = zeros(size(X0));
    " l: S! y( a1 s6 tend
    6 B4 H0 [- t' X. j+ o6 Uif ~ischar(init)
    7 p% C- v0 m" {% E    X0 = init;% T2 P* `; P$ [. h" I0 T' r% {
    end
    4 m+ p7 R! r* O9 i: v0 x8 ~! z- |& i) Yif nargout>1$ L: k- i5 g7 t; f! n+ H4 `, g" Y2 \
        xi = X0;8 f( G, w0 M2 G" X8 c7 j
    end
    ) p7 B+ s1 A1 w" f; @) B2 C[xnr,xnc]= size(X0);
    ) g: ]; @8 [" o- U! b2 Oif xnc~=1 && xnc~=Ne6 j8 U: N( D; C" d- F( ^, {
        error('Ident:analysis:IniSize',...9 Q- {7 g4 b! e' Q! Z; a
            'The "InitialState" option value must have either 1 or Ne columns, where Ne = no. of data experiments.');
    : d( _* ?: ^) A5 I/ O& y: Kend
    / A8 @2 F1 |/ ~3 z6 c" B) tif xnr~=nx% i% a/ H; m8 K6 @% _
        error('Ident:analysis:IniRows',...$ C8 P1 \1 J# S$ o) E
            'The value of the "InitialState" option should have %d row(s).',nx)
    : _3 E/ A& a# v! ]/ R: [3 Dend+ k2 z+ n, P4 m9 x( M6 A$ k$ q
    if xnc==1 && Ne>12 }  ~/ K2 g! }! g2 K4 i, A' n0 k, B
        X0= X0*ones(1,Ne);  T- \+ {: y2 v! ^1 _0 m$ ~. B4 S: [
    end
    3 [- d. e# K/ u  ]for kexp = 1:Ne2 G4 l! P9 ?' X  m1 g
        z = ze{kexp};7 s) K# D% w9 p# L+ k" L. H
        u = z(:,1+ny:end);0 F% |: P- H5 w* ]
        Ncap = Ncaps(kexp);' R' X  J& v5 c
        if m==inf,
    : L* k& p; u7 q  k: S$ R2 i; Y- [        yhat=sim(theta,u,X0(:,kexp));
      }* r- n1 q7 v' D3 h- w    else1 n* b: \) `+ h+ M. a8 i
            x=ltitr(A-K*C,[K B-K*D], z, X0(:,kexp));3 U6 [4 @$ q! c/ P% d  L
            if m==1,1 o0 p6 r) f; Z
                yhat=(C*x.').';
    + d5 p2 l; w8 o. Z/ S            if ~isempty(D),yhat=yhat + (D*u.').';end
    0 T2 y3 F- S" K. w/ P* t4 h7 m        else, q) G' a' G4 s3 H, U* E0 ]4 U! x% M
                F=D;Mm=eye(length(A));. C1 j  h( s4 s# ?9 H
                for km=1:m-1- w% i4 P3 z6 |' e' N& ?
                    F=[F C*Mm*B];" b) ^3 A3 l; Q$ |
                    Mm=A*Mm;8 N) C( A- Q* T
                end* i' P9 i4 }4 s: R: o
                yhat=zeros(Ncap,ny);%corr 911111
    " I8 f. Q9 }* J0 p            for ky=1:ny7 y+ \4 M) `1 g9 z+ p+ \
                    for ku=1:nu
    $ s' e# M/ K0 d1 p8 a) p                    yhat(:,ky)=yhat(:,ky)+filter(F(ky,ku:nu:m*nu),1,u(:,ku));
    8 I5 l. c+ S# }, P                end5 q; m& W# S, X" o' a
                end, _! m) F4 y) Z* z
                if isempty(yhat),yhat=zeros(Ncap,ny);end" G* O! S, c/ Q. r/ c* S
                yhat(m:Ncap,:)=yhat(m:Ncap,:)+(C*Mm*x(1:Ncap-m+1,:).').';" B3 N  U' E2 b5 M8 j
                if nu>01 `3 T3 b  u( f0 X% x4 U
                    x=ltitr(A,B,u(1:m,:),X0(:,kexp));
    & |" b% @4 R& F: D* q) |                yhat(1:m,:)=(C*x.').';5 x0 @( w( O* I  L
                end
    9 H% }/ N. _5 S2 u            if ~isempty(D),yhat(1:m,:)=yhat(1:m,:) + (D*u(1:m,:).').';end( V, l8 {6 p9 {. r; e
            end
    ' |* A' E8 c5 K% x$ E6 ~: _    end7 g5 u2 g6 t4 B/ o
        yhatc{kexp} = yhat;2 l* Y* O: E$ Y# u5 \
    end
    / Z' \  A2 o3 |0 P* n6 wif iddatflag; s! r" _' c2 g: T4 t/ Y- w! r& i
        yhat = data;
    9 ^0 B2 s) r2 i2 i( C    yhat = pvset(yhat,'OutputData',yhatc,'InputData',[]);+ J+ y. x1 B; h" P
    else) j6 P( _; ?# S! x0 ~/ E
        yhat = yhatc;9 q8 g, z1 l* u) p3 D& H
    end1 `. n$ s+ u2 `1 S
    if nargout >2' I. w) r9 p7 t( l6 d  ?+ O
        thpred = polypred(theta,m);& \+ ]. \) }1 [8 \
    end9 U% F  f2 Q9 y" H4 a
    if nargout > 1
    / I* o- _) A/ j8 R9 o$ x" h    try9 ?/ O, H# I1 o' _3 a
            xi = xi(1:nxorig,:);/ d5 s: Q0 K' d+ ?0 }
        end
    ( x, ?& V7 k; c& Q/ Iend8 E. C" d( ^& ^8 o6 l7 M& L; }
    if (nargout == 0)
    % ~- K1 C0 h+ C4 o# P# m1 @: _    % Plot y and yhat.* o. P) [' h, s4 g
        utidplot(theta,yhat,'Predicted');
      r$ f! s  ^( d* V$ ~    clear yhat x0;) F. l8 [, D0 v6 b+ Y5 p
    end
    ' ]/ y- B, T$ W%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%- i: A1 @3 J" ?3 R
    %%%%% LOCAL FUNCTIONS
    * O5 t9 {6 [$ t. q0 n- l7 _  i%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0 l" B/ e9 o5 Nfunction xi = x0iniest(m,data)2 N8 k# b5 p5 Q1 |- O6 K$ Z6 V
    if isa(data,'iddata') && strcmpi(pvget(data,'Domain'),'frequency')
    3 l' `% f; z4 U# q% a    [dum,xi] = pe_f(m,data);; |8 l  A7 j2 N& M7 H/ y5 R* g
        return6 Q. J  [7 U% @! n2 N; Q
    end
    # N' Y2 r) V  S" LInpd = pvget(m,'InputDelay');
    ) z  H4 g/ a( Qif isa(data,'iddata')
    ; A* O0 O& d+ t3 @: X    data = nkshift(data,Inpd,'append');1 v, v) |* S' T4 ~
        [ze,Ne,ny,nu,Ts,Name,Ncaps,errflag] = idprep(data,0,'dummy');
    5 {) _' W4 I* k. `    %if ~isempty(errflag.message), error(errflag), end* e& F5 K" `: B; o5 j0 V5 N
        if ~isempty(Name)
    ) E/ s9 }' l) ^        data.Name = Name;/ v/ e2 j( }. q8 l  i- Z
        end
    . B) D+ P( j3 i8 Melse. G9 p; ~! g' B% b/ D& B
        if iscell(data)
    2 M6 ?" o3 Z* w% J' S% v        ze = data;
    9 p! }/ v' D# B$ _    else! Y! X# H- K/ T2 ~: Z( _7 F. P
            ze = {data};
    ! u5 h7 S% J$ [0 B6 O& R$ S    end- q  Y2 T4 y3 y6 Q
    end
    - V8 Y. ]7 P' \9 xalg=pvget(m,'Algorithm');
    . E  d1 ^4 s3 u, ?/ ?/ Q6 fmaxsize=alg.MaxSize;
    , ^5 W" p. c8 x6 M8 \% p[A,B,C,D,K,X0]=ssdata(m);2 ]; P. g% U& b6 F8 [* \$ a4 y
    nx=length(A);  d* W* g0 T5 ~
    if ischar(maxsize)
    % Y  j- V5 ^4 h7 N    maxsize = idmsize(length(ze{1}),nx);  m! E! d& z: g9 A! J: E" l
    end; }; Q- x0 v# C" |" A; ?
    AKC=A-K*C;
    " j+ _$ }0 X5 I4 \- S[ny,nx]=size(C);& a3 k# ]7 w. R- U0 u& U: K2 |
    nu=size(B,2);5 w" W$ G* R' p6 A
    el=zeros(0,ny);( T# Y! f# P$ ^) B
    xic = zeros(nx,0);) `2 v5 u; |& d9 @* v
    Ne = length(ze);+ |8 x! L% e4 l3 C: _
    for kexp = 1:Ne
    " Y( K; Y; L6 z" h# O0 o    z = ze{kexp};1 R6 d7 o- m0 k
        [Ncap,nz]=size(z);) \- N. z6 W' E8 J
        if nu+ny~=nz# w$ ]1 C% U- Y: e: V
            error('Ident:general:modelDataDimMismatch',...
    " C' C( _6 ]; v  h2 s            'The number of inputs and outputs of the model must match that of the data.')
      R) C0 _" N0 d- Q( U    end. f, M' i( }# L& \) c
        nz=ny+nu; [Ncap,dum] = size(z); n = nx;
    : Q! F' }: i: k) S5 B6 ~    rowmax = nx+nz; X0 = zeros(nx,1);$ y3 w# L+ P  ?" C7 \8 y* l" ^- M, a0 m+ M
        M=floor(maxsize/rowmax);+ y; `8 Y2 @% \1 L6 l$ J
        if ny>1 || M<Ncap
    1 u" V, ~- T( r6 X) @0 d1 e        R=zeros(n,n);Fcap=zeros(n,1);R1=[];
    0 s4 N1 V; i" [$ {% N; o  O6 Y        for kc=1:M:Ncap) v* Q+ c; w  E  U0 |2 m
                jj=(kc:min(Ncap,kc-1+M));
    5 g: g' y+ a% @" w# h, y9 @            if jj(length(jj))<Ncap
    + G5 t# Y* L, k# U# j' ^: L1 w/ A$ h8 N                jjz = [jj,jj(length(jj))+1];: f) X( b3 [' C2 t# x& m: c
                else% E( `7 n& e8 ^! i/ G
                    jjz=jj;* P# o/ l' c/ o9 o: [. k" Z: r9 t
                end
    $ [, I0 `7 m7 G6 W            psitemp=zeros(length(jj),ny);; [1 h" Q$ C  K' @" t/ m
                psi=zeros(ny*length(jj),n);0 i$ Z- |$ `  m, J  K/ T
                x=ltitr(AKC,[K B-K*D],z(jjz,:),X0);
    1 w* q& n& t7 u            yh=(C*x(1:length(jj),:).').';6 u- [' |7 ], q4 E% Y2 l! V
                nm=pvget(m,'NoiseVariance');& n4 R8 s- K) v. M1 C
                if isempty(nm) || norm(nm)==0 % To handle models without noise, z7 |5 P& d& N" l$ U
                    nm = eye(ny);
    4 a" j4 l) j' F/ k8 f. [0 }            end6 W7 E' w* _. D) R
                sqrlam=pinv(sqrtm(nm));
    6 e% v1 }  M2 M/ l            if ~isempty(D),yh=yh+(D*z(jj,ny+1:ny+nu).').';end2 p7 |1 H% O/ b" U: S, }6 f
                e=(z(jj,1:ny)-yh)*sqrlam;
    % V( k+ R. r% C2 x$ U            [nxr,nxc]=size(x);X0=x(nxr,:).';
    7 R9 `8 E7 w& a1 U+ N* L            evec=e(:);8 L* F- Q4 l1 }! s' M$ v2 n) F" [
                kl=1;9 S) F4 i( V$ r+ `( ]+ M
                for kx=1:nx
    2 t4 R: q  }% L9 i3 P2 k                if kc==10 z# a9 v9 B; I+ b
                        x0dum=zeros(nx,1);x0dum(kx,1)=1;% _% H) J! O$ @: p$ Z
                    else$ E2 g# z, m5 h% V* Y: X
                        x0dum=X00(:,kl);
    & ^, l' B( t4 s, l4 x/ `                end: x) n/ H2 w" y6 q! v
                    psix=ltitr(AKC,zeros(nx,1),zeros(length(jjz),1),x0dum);- W0 u' t8 `& ]& Q* J2 O- `1 U
                    [rp,cp]=size(psix);: ?, a3 _% `4 \% `2 a" N
                    X00(:,kl)=psix(rp,:).';
    ( i; t3 m7 R2 M                psitemp=(C*psix(1:length(jj),:).').'*sqrlam;' T6 R/ z* }) w+ p; G
                    psi(:,kl)=psitemp(:);kl=kl+1;# s. p& D1 }& {2 d- P  a& o
                end' K% E* g" k0 y) X4 @
                if ~isempty(R1)( G# S/ K- ~  ?8 R8 g
                    if size(R1,1)<n+1  [9 f; d* b6 l
                        error('Ident:estimation:predictSmallMaxSize',...7 [$ u; u) b, h' v, N
                            'The value of the algorithm property "MaxSize" is too small to estimate the initial states. Either increase MaxSize value in the model or set the "InitialState" option of the "predict" command to a value other than ''Estimate''.')
    ' O5 i* P' v7 P" d  d9 j( I5 i4 r                end9 ?; d& ^9 E( U0 U
                    R1=R1(1:n+1,:);
    " G- H; g6 m& Y- K& a2 Y5 Q            end! E; f" ]9 j) H- b1 F4 }6 X# G
                H1 = [R1;[psi,evec] ];R1 = triu(qr(H1));
    5 O$ B0 U" u5 v3 g4 Z/ w        end0 X6 B$ `& [6 l) c- K" E$ I- V8 s
            try
    # I4 P, O. X9 ^: X* N* d            xi(:,kexp) = pinv(R1(1:n,1:n))*R1(1:n,n+1);
      ]1 ?2 v. N( H- X) G' V0 j- m0 i        catch' B1 }3 a. R' w! S
                warning('Ident:estimation:X0EstFailed',...0 ~, k6 e* u0 C$ U) F1 V
                    'Failed to estimate initial conditions. Check model stability. \nThe "InitialState" option has been set to zero.')
    $ D8 I, f: g0 B1 l; X6 E- U            xi(:,kexp) = zeros(n,1);
    2 z# T8 G/ d7 x        end
      U2 M5 j0 [% |9 @8 i/ S' y: W- P5 C    else
    & l# ^7 f0 P3 ]- {        %% First estimate new value of xi; I5 r# s; q3 _. q: [8 {0 `
            x=ltitr(AKC,[K B-K*D],z);% _6 v1 C8 v: x# {
            y0=x*C';
    + W. g* x+ D% ?$ J        if ~isempty(D),; M) y* O4 R% [# o7 l" ]
                y0=y0+(D*z(:,ny+1:ny+nu).').';( w3 B! O. B' R$ G4 j
            end; Q) }, V9 r, d! u4 @, V( ^, A; S( U- p
            psix0=ltitr(AKC.',C.',[1;zeros(Ncap,1)]);
    ! E6 w7 N. v: d  i        psix0=psix0(2:end,:);9 U1 O, A. Q. J# M+ n% {* U
            try
    + X0 m; A/ z  y) c2 t$ k            xi(:,kexp) = pinv(psix0)*(z(:,1)-y0);
    ) A3 ~* V  m9 P, `5 }        catch
    ' j% C- ~/ k) a  ?0 p8 ?# e0 B            warning('Ident:estimation:X0EstFailed',...( c! r! U1 |$ |& j# E; s& a) C
                    'Failed to estimate initial conditions. Check model stability. \nThe "InitialState" option has been set to zero.')# G0 Y9 J# H9 y
                xi(:,kexp) = zeros(n,1);+ F# _. [% Q+ w. ^4 O& l
            end
    2 b5 ~" B4 H9 D. g    end
    8 g7 m' o, @  [( Jend
    ' l3 i2 u1 L7 {0 R# @%%*************************************************************************# _& F& `3 g1 {) ]" K
    function thpred = polypred(theta,m)* Y6 Y" a' E5 b* ]- Z- K: L' u
    % Note that cross couplings between output! E* U) ~* {6 ?; G6 M
    % channels are ignored in these calculations.
    : U3 ?. ?1 f$ r0 Z: c[ny,nu]= size(theta);
    5 M5 c7 ~9 ]" D$ P/ G$ Q! G) @6 C5 ayna = pvget(theta,'OutputName');
      i+ w- P4 o( B5 ^2 @una = pvget(theta,'InputName');
      Q7 j" N" K8 ~, r6 T! p7 c! J$ O7 W1 xyu = pvget(theta,'OutputUnit');
    ( @  y4 j7 V  ?/ U2 puu = pvget(theta,'InputUnit');
    ! C! A0 U, L3 u% M, }6 Afor ky = 1:ny
    & y1 x9 Y% m- Z5 q) o& d1 [: q    [a,b,c,d,f] = polydata(theta(ky,:));! Q$ o& a- g9 b' ?% w0 F: m1 R
        if nu>0
    ' f8 s/ C8 ~, j) ~! U# f0 N        ff = 1;
    , F5 f1 o  M! l# Z! J& c% V        for ku = 1:nu,7 }- x% Z  U2 ~- o( `' [
                bt = b(ku,:);- @5 J% W. \. k3 j' ?! Q
                for kku = 1:nu, if kku~=ku, bt = conv(bt,f(kku,:)); end, end
    ' E- s' T( V8 I$ L) m1 e/ E5 y- i            bb(ku,:) = bt;
    : d/ I. N( a  y) p8 h% r, J            ff = conv(ff,f(ku,:));
    3 O" m8 P4 W* F        end1 a7 e# U4 v+ v" S
            a = conv(conv(a,ff),d);c=conv(c,ff);! g# R8 A0 [4 z4 {3 O: g7 ]. l
        else
    2 Y  q4 ?; Z' F; \/ p" N- J        a = conv(a,d);) z7 [% l/ ]: M. ?; [& q7 n9 {
        end5 j0 x% J) x' @2 V3 Y- Q9 d
        na = length(a); nc = length(c); nn = max(na,nc);* y& \: C# m# L# M( _
        a = [a,zeros(1,nn-na)]; c = [c,zeros(1,nn-nc)];
    ; `" f$ U( w$ {* G& Z! w0 b6 }4 j    [f,g] = deconv(conv([1 zeros(1,m-1)],c),a);
    $ o  M9 u" W# c! S: f" `    ng=length(g);
    . [* z2 a% @, _+ G& y0 H    if nu>0,
    ) u$ Y) i* `8 y& N! N1 M# a        df=conv(d,f);6 V; {  x' c: b% U1 R& T& ?, g0 ^
            for ku=1:nu
    ! e3 b5 E' Y# [% q' L! D9 G' O            bf(ku,:)=conv(bb(ku,:),df);& p9 k" P  |9 M
            end3 X5 x1 G/ d- _) \) A
            nbf=length(bf(1,:));nn=max(ng,nbf);
    9 A4 x5 f" i" O6 E* x        gg=[[g,zeros(1,nn-ng)];[bf,zeros(nu,nn-nbf)]];
    ; n' C8 H/ j; f5 ?    else5 b1 |* F$ m' _! N
            gg=g;
    9 Q2 V5 N! ]/ K0 {5 H6 Y9 z    end
    ( h7 K* N; \( ]7 s' [    th1 = idpoly(c,gg);' S1 r- k- T( z% f: V
        th1 = pvset(th1,'InputName',[yna(ky);una],'OutputName',[yna{ky},'p'],...
    $ @1 i; N1 n+ d5 P) |0 @        'InputUnit',[yu(ky);uu],'OutputUnit',yu(ky),'Ts',pvget(theta,'Ts'),...
    ; [) ~) c; p- R0 o# ^. \; x, }        'TimeUnit',pvget(theta,'TimeUnit'),'EstimationInfo',pvget(theta,'EstimationInfo'));  Y1 G+ ?0 k* E8 l: a
        thpred{ky} = th1;6 K! Q0 Z2 r1 h( w" W5 c/ @$ F
    end
    . Y7 p. Y$ Y$ `1 H+ q4 g( c%%%************************************************************************
    "真诚赞赏,手留余香"
    还没有人打赏,支持一下
    帖文化:【文明发帖 和谐互动】 社区精神:【创新、交流、互助、共享】
    您需要登录后才可以回帖 登录 | 立即加入

    本版积分规则

    招聘斑竹

    小黑屋|手机版|APP下载(beta)|Archiver|电力研学网 ( 赣ICP备12000811号-1|赣公网安备36040302000210号 )|网站地图

    GMT+8, 2025-2-23 10:13

    Powered by Discuz! X3.5 Licensed

    © 2001-2025 Discuz! Team.

    快速回复 返回顶部 返回列表