www.gusucode.com > ident 案例代码 matlab源码程序 > ident/ForecastReposneOfTwoOutputNonlinearTimeSeriesModelExample.m
%% Forecast Response of Multi-Output Nonlinear Time Series Model %% % Load data. load(fullfile(matlabroot,'toolbox','ident','iddemos','data','predprey2data')); z = iddata(y,[],0.1); set(z,'Tstart',0,'OutputUnit',{'Population (in thousands)',... 'Population (in thousands)'},'TimeUnit','Years'); %% % |z| is a two output time-series data set (no inputs) from a 1-predator 1-prey % population. The population exhibits a decline in predator population due % to crowding. The data set contains 201 data samples covering 20 years of % evolution. % % The changes in the predator (|y1|) and prey (|y2|) population can be % represented as: %% % % $$y_1(t) = p_1*y_1(t-1)+p_2*y_1(t-1)*y_2(t-1)$$ % % $$y_2(t) = p_3*y_2(t-1)-p_4*y_1(t-1)*y_2(t-1)-p_5*y_2(t-1)^2$$ % %% % The nonlinearity in the predator and prey populations can be fit using a % nonlinear ARX model with custom regressors. %% % Use part of the data as past data. past_data = z(1:100); %% % Specify the standard regressors. na = [1 0; 0 1]; nb = []; nk = []; %% % Specify the custom regressors. C = {{'y1(t-1)*y2(t-1)'};{'y1(t-1)*y2(t-1)','y2(t-1)^2'}}; %% % Estimate a nonlinear ARX model using |past_data| as estimation data. sys = nlarx(past_data,[na nb nk],'wavenet','CustomRegressors',C); %% % Compare the simulated output of |sys| with measured data to ensure it is % a good fit. compare(past_data,sys); %% % Plot the forecasted output of |sys|. forecast(sys,past_data,101); legend('Measured','Forecasted');