0

I want to simulate a time series y1 with an AR(p) process, and then solve the differential equation dy/dt = AR(p)(y1). This is the Scilab code I wrote (the AR coefficients are calculated with the lev() function and then normalized in a part of the code I omitted to keep it short).

  t = [0:0.1:2*%pi];
  y1 = sin(t);
  C = 1;
  y2 = -1*cos(t) + C;
  ar = [1.  - 0.0195380  - 0.0154317  - 0.0116690  - 0.0081661  -0.1015448]
   y1_m = filter(1, ar, y1); //Generates simulated series
  function y_m = far(t, y, ar, y1)
      y_m = filter(1, ar, y1);
  endfunction
  //Solves ODE
  y0 = y1(1); t0 = t(1);
  y2m = ode(y0, t0, t, list(far, ar));
  scf(1); plot(t, y2, '-k', t, y2m, '.k');

However, the code fails with message:

y2m = ode(y0, t0, t, list(far, ar_n));
                                  !--error 98
La variabile restituita dalla funzione argomento di Scilab non è corretta.
at line      26 of exec file called by : 

How can I solve this ODE?

Added Case Description: What I have is a system that performs certain operation on the input signal Y, which is a time series, producing an output Z. The system equations are known, so I can determine Z provided that Y is a known function of time.

And by writing that I realize where my mistake lies: with an AR model, I am expressing Y not as a function of time, but of its own past values.

So I should rather ask, how can I fit a function of time to a time series?

Fabio Capezzuoli
  • 599
  • 7
  • 23
  • I noticed that you do ``ar = [...]; y1_m = filter(1, ar_n, y1)``. Shouldn't ``ar`` be named ``ar_n``? If yes, I ran you code on Scilab 6.0.0 and there was no error. – luispauloml Nov 29 '17 at 09:15
  • Your ODE function `far` should depend on `y`. In `list(far, ar_n)` there is no argument for the place of `y1`. If I interpret this right, are you trying to solve `y' = T^(-1)*y` where `T` s a Töplitz matrix defined by the entries of `ar`? – Lutz Lehmann Nov 29 '17 at 09:24
  • @luispauloml. In fact you caught a mistake I made while inputting the code in Stackoverflow. I corrected the question, – Fabio Capezzuoli Nov 29 '17 at 09:45
  • @LutzL. Also using `y2m = ode(y0, t0, t, list(far, ar, y1));` the result is the same. I am not familiar with the Toplitz matrix, so I cannot say. – Fabio Capezzuoli Nov 29 '17 at 09:52
  • From the look of it, `far` returns a constant, so the solution should be linear functions. Is that the desired result? – Lutz Lehmann Nov 29 '17 at 10:18
  • Please describe what exactly you want to compute, I have the feeling that using `ode` is completely inappropriate for that task, as it looks like you are simulating a discrete dynamical system. – Lutz Lehmann Nov 29 '17 at 10:36
  • No, it's not. The desired result should be close to `y2`, the analytical solution. – Fabio Capezzuoli Nov 29 '17 at 10:37
  • Yes, I think this problem requires a complete explanation. Please stay tuned for it. – Fabio Capezzuoli Nov 29 '17 at 10:39
  • Indeed in https://en.wikipedia.org/wiki/Autoregressive_model there is no mention of differential equations. – Lutz Lehmann Nov 29 '17 at 10:39
  • In `dy/dt = AR(p)(y1)` the right side is a constant. Or one has to describe what `y` is in relation to `y1` and what dimensions are involved. By itself, the right side should return a finite sequence. You seem to consider `y` to be scalar. – Lutz Lehmann Nov 29 '17 at 10:47
  • Can it be that you want to compute and confirm the discretized linear system for a given and perhaps unknown continuous linear system? – Lutz Lehmann Nov 29 '17 at 10:56
  • I added an extended description of my case. – Fabio Capezzuoli Nov 30 '17 at 03:33

0 Answers0