I am using the “integrate_ode” function to obtain the integrate of a differential equation. One argument is: x_r: real data, type real[]. However, my data input consists of several components, i.e., two vectors with different size, and a matrix. How can put all my input in this x_r argument?

One element at a time. You usually also have to specify x_i as the indices of things so that you can put the elements of x_r into a vector, matrix, etc. on the inside of the function being integrated.

For example, my input data have a vector “x” with size 3, another vector “z” with size 5, and a matrix with 100 rows and 3 columns. They are all needed for my function being integrated.

How can I combine all these elements together into x_r as the type real[]? Then I will pass it to the “integrate_ode” function.

int x_i[4] = {3, 5, 100, 3};
int pos = 1 + x_i[1] + x_i[2];
real x_r[x_i[1] + x_i[2] + x_i[3] * x_i[4]];
for (k in 1:x_i[1]) x_r[k] = x[k];
for (k in 1:x_i[2]) x_r[k + x_i[1]] = z[k];
for (i in 1:x_i[3]) for(j in 1:x_i[4]) {
x_r[pos] = m[i,j];
pos += 1;
}