13,829,868 members
See more:
Dear all,
I'd like to use time series analysis for predicting a future value i.e. energy consumption in simuator but i don't know how to do it in c++.Can anyone guide me or give me some example?

thanks
Posted

## Solution 1

Did you Google for?
A starting point could be Wikipedia's Time series[^] page.

## Solution 2

Hi,
The best and faster way to do this is use a numeric software, like matlab.
if you want to implement it in c++, i advice you to use some existent forecast library.

You have a lot of models to forecast, such as auto regressive models (AR, ARX, ARMA, ARMAX, ARIMA, ...), fuzzy models, neural networks models, support vector machines models, markov chains, and so on...

This is just a simple model:
y(k)+a1y(k-1)+a2y(k-2)+...+any(k-n) = b1u(k)+b2u(k-1)+...+bmu(k-m)

Where y is your output and u is your input. 'a' and 'b' are coefficients that you can calculate them by minimizing some cost function.

Here is a example in c++ to calculate the future value (i did not tested it, there may be errors)

```double forecast(double *y, double *u, bouble *a, double b)
{
double future_value = 0.0;

//y to the instant k
future_value = b[0]*u[0]+b[1]*u[1]+...+b[m-1]*u[m-1]-a[0]*y[0]+a[1]*y[1]+...+a[n-1]*y[n-1];

for(int i = 1; i < n; i++)
{
y[i] = y[i-1];
}
y[0] = future_value ;

//I assume that the input array is updated before you call this function
}```

Again, I suggest to use some numerical software that brings such algorithms implemented.

Otherwise, google is the best way to start

Best regards
Filipe Marques

## Solution 3

thank you for all of your comments.At first i'm thinking to use matlab but my value got from network simulator(ns2).I think it will be tough to link these two program.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Richard MacCutchan 160 OriginalGriff 70 Dylvh 50 Maciej Los 50 Graeme_Grant 45
 OriginalGriff 2,776 Maciej Los 1,480 RickZeeland 1,375 Richard MacCutchan 1,233 Wendelius 870