www.gusucode.com > econ 案例源码程序 matlab代码 > econ/timeVariantParamMap.m
% Copyright 2015 The MathWorks, Inc. function [A,B,C,D,Mean0,Cov0,StateType] = timeVariantParamMap(params) % Time-variant state-space model parameter mapping function example. This % function maps the vector params to the state-space matrices (A, B, C, and % D), the initial state value and the initial state variance (Mean0 and % Cov0), and the type of state (StateType). From periods 1 through 10, the % state model is an AR(2) and an MA(1) model, and the observation model is % the sum of the two states. From periods 11 through 20, the state model is % just the AR(2) model. varu11 = exp(params(3)); % Positive variance constraints vare11 = exp(params(6)); vare12 = exp(params(8)); A1 = {[params(1) params(2) 0 0; 1 0 0 0; 0 0 0 params(4); 0 0 0 0]}; B1 = {[sqrt(varu11) 0; 0 0; 0 1; 0 1]}; C1 = {params(5)*[1 0 1 0]}; D1 = {sqrt(vare11)}; Mean0 = [0.5 0.5 0 0]; Cov0 = eye(4); StateType = [0 0 0 0]; A2 = {[params(1) params(2) 0 0; 1 0 0 0]}; B2 = {[sqrt(varu11); 0]}; A3 = {[params(1) params(2); 1 0]}; B3 = {[sqrt(varu11); 0]}; C3 = {params(7)*[1 0]}; D3 = {sqrt(vare12)}; A = [repmat(A1,10,1);A2;repmat(A3,9,1)]; B = [repmat(B1,10,1);B2;repmat(B3,9,1)]; C = [repmat(C1,10,1);repmat(C3,10,1)]; D = [repmat(D1,10,1);repmat(D3,10,1)]; end