forecast

Forecast linear system response into future

Syntax

yf = forecast(model,past_data,K)
yf = forecast(model,past_data,K,future_inputs)
yf = forecast(model,past_data,K,___,opt)
[yf,x0efmod] = forecast(model,past_data,K,___)

Description

yf = forecast(model,past_data,K) forecasts the output of a linear identified time series model, model, K steps into the future using the historical output data record, past_data. In this case, future denotes the time samples beyond the last sample time in past_data.

yf = forecast(model,past_data,K,future_inputs) uses the future values of the inputs to model, future_inputs to forecast the response of an input-output model.

yf = forecast(model,past_data,K,___,opt) forecasts the future output of model using the option set opt to specify the forecasting algorithm options.

[yf,x0efmod] = forecast(model,past_data,K,___) returns the estimated values for initial states, x0e, and a forecasting model, fmod.

Input Arguments

model

Identified linear model.

past_data

Historical input/output values.

If model is a time-series model, which does not have input signals, then past_data can be specified as:

  • An iddata object with no inputs

  • A matrix of historical time-series data

K

Time horizon of the forecast.

K must be a positive integer that is a multiple of the sampling time of the data, past_data.Ts.

future_inputs

Future values of inputs to model.

Specify future_inputs for the time interval past_data.Tstart + (N+1:N+K)*past_data.Ts, where N is the number of samples in past_data.

future_inputs must be a matrix of size [K, Nu], where K is forecast horizon and Nu is the number of inputs.

future_inputs is only relevant if model is not a time-series model.

Alternatively, use an iddata model to specify future_inputs.

Use [] if model is a time-series model.

If past_data is specified for multiple experiments, then specify future_inputs as:

  • A multiexperiment iddata object

  • Cell array of matrices, with an array entry for each corresponding past_data experiment data set

Default: 0

opt

Options set for forecast.

Use forecastOptions to define options.

Output Arguments

yf

Forecasted response.

yf is the forecasted response at times after the last sample time in past_data. In true time, yf contains data for the time interval past_data.Tstart + (N+1:N+K)*past_data.Ts. N is the number of samples in past_data.

x0e

Estimated initial states.

x0e is returned only for state-space systems.

fmod

Forecasting model.

fmod is a dynamic system whose simulation, using future_inputs and x0e, yields yf as the output.

fmod is always a discrete-time system.

If past_data is specified for multiple experiments, then fmod is an array of dynamic models, with each entry corresponding to an experiment in past_data.

Examples

expand all

Forecast Future Values of a Sinusoidal Signal

Forecast the values of a sinusoidal signal using an AR model.

Generate and plot data.

data = iddata(sin(0.1*[1:100])',[]);
plot(data)

Fit an AR model to the sine wave.

sys = ar(data,2);

Forecast the values into the future for a given time horizon.

K = 100;
p = forecast(sys,data,K);

K specifies the forecasting time horizon as 100 samples. p is the forecasted model response.

Analyze the forecasted data.

plot(data,'b',p,'r'), legend('measured','forecasted')

Forecast Response of Time-Series Model

Forecast the response of a time-series model for a given number of time steps in the future.

Obtain a time-series model and past data.

load iddata9 z9
model = ar(z9,4);
past_data = z9.OutputData(1:51); % double data

z9 is an iddata object that contains the measured output only.

model is an idpoly time-series model.

past_data contains the first 51 data points of z9.

Forecast the system response into the future for a given time horizon.

K = 100;
yf = forecast(model,past_data(1:50),K);

K specifies the forecasting time horizon as 100 samples, with the same sampling time as past_data.

yf is the forecasted model response.

Analyze the forecasted data.

t = z9.SamplingInstants;
t1 = t(1:51);
t2 = t(51:150)';
plot(t1,past_data,t2,yf,'r')
legend('Measured','Forecasted')

Forecast Model Response Using Future Inputs

Obtain past data, future inputs, and identified linear model.

load iddata1 z1
z1 = iddata(cumsum(z1.y),cumsum(z1.u),z1.Ts,'InterSample','foh'); % integrated data
past_data = z1(1:100);
future_inputs = z1.u(101:end);
model = polyest(z1, [2 2 2 0 0 1],'IntegrateNoise',true);

z1 is an iddata object that contains integrated data. model is an idpoly model. past_data contains the first 100 data points of z1. future_inputs contains the last 200 data points of z1.

Forecast the system response into the future for a given time horizon and future inputs.

K = 200;
yf = forecast(model,past_data,K,future_inputs);

K specifies the forecasting time horizon as 200 samples, with the same sampling time as past_data.

yf is the forecasted model response.

Analyze the forecasted data.

plot(past_data,yf);
legend('Measured','Forecasted')

Was this topic helpful?