How to add a known time series vector into ODE

Borrowing the ODE example from the stan documentation, I have an ODE system with one know time-dependent vector (vector Z[T] = [integers]). I know I need an interpolation function to use Z_t[i] in each step of ODE solver and use in transformed parameters as well. I have changed the code as below but cannot define the function and make it work:


functions {
real[] intropolation(){
}
real[] sir(real t,
real[] y,
real[] theta,
real[] x_r,
int[] x_i) {

real 
real dydt[3];

z_t= intropolatin()
dydt[1] = -theta[1]* y[2] * y[1] ;
dydt[2] = theta[1]* y[2] * y[1] - theta[2]* y[2] + z_t;
dydt[3] =  theta[2]*  y[2];

return dydt;
}
}
data {
int<lower=1> T;
real y[T,3];
real t0;
real ts[T];
vector[T] Z;
}
transformed data {
int x_i[0];
real x_r[T];
for (i in 1:T){
    x_r[i] = Z[i];
}
transformed parameters{
  real y[T, 3];
  real cases[T - 1];
  {
    y = integrate_ode_rk45(sir, y0, t0, ts, theta, x_r, x_i);
  }
  for (i in 1:T-1){
   cases[i] =  y[i, 1] - y[i+1, 1] + Z[i];
  }
}

Thank you in advance for your help.
#modeling #Interpolation #ODE solver #Bio

Maybe

functions {
  real interpolation(real time, int T, vector Z){
    /* interpolation scheme using Z and current time */
  }

  vector sir(real t, vector y, real theta, int T, vector Z) {
    vector[3] dydt;

    dydt[1] = -theta[1]* y[2] * y[1] ;
    dydt[2] = theta[1]* y[2] * y[1] - theta[2]* y[2] + interpolation(t, T, Z);
    dydt[3] =  theta[2]*  y[2];

    return dydt;
  }
}
/* ... */
transformed parameters{
  array[T] vector<3> y;
  y = ode_rk45(sir, y0, t0, ts, theta, T, Z);
  /*...  */
}
/* ... */

See details in doc: 13.4 Measurement error models | Stan User’s Guide.

Thank you, @yizhang