Maybe I need to reformulate(?). Suppose there is this simple function:
$$f(x)=\int_a^b{x \text{d}x}$$
If it were to be discretized, there would be losses due to sampling. In order for the errors to be minimized, one can apply Gauss-Legendre, or similar. Now, in this case, it's simple, convert the limits, apply quadrature, since the function is known and can be calculated at any time without the knowledge of past values.
[edit]
But say you have a function which is recursive, that is, the output, $y$, is a function of the input, $x$ (known all the time), but depends on itself, too, so I am unsure whether $y=f(x)$ or $y=f(x,y)$, because then it can be written as $y=f(x,f(x,y))$, which is $f(x,f(x,f(x,f(...))))$... I'll choose the former, for simplicity:
$$y = f(x)$$ $$y=\frac 1 {b_2}\left[a_2 x+\int^{t_1}_{t_0}{\left(a_1 x-b_1 y+\int^{t_2}_{t_1}{(a_0 x-b_0 y) \text{d}x}\right)\text{d}x}\right]=$$ $$\frac 1 {b_2}\left[a_2 x+\int^{t_1}_{t_0}{\left(a_1 x-b_1 f(x)+\int^{t_2}_{t_1}{(a_0 x-b_0 f(x)) \text{d}x}\right)\text{d}x}\right]\text{?}$$
$t_0$, $t_1$, and $t_2$ are the sampling times. Since there is an integral whithin an integral, the timings differ (as also seen in the code below).
[/edit]
Can Gauss-Legendre still be applied in this case? If not quadrature, maybe other method? If yes, how?
The reason for this is to implement it in C++. This simple test code came up (a is the vector made of $[a_{2,1,0},b_{2,1,0}]$, u is the input signal, y is the output vector, and T is the sampling period):
void f(const std::vector<double> &a, const std::vector<double> &u, std::vector<double> &y, const double &T)
{
int n {static_cast<int>(u.size())};
std::vector<double> y0(n), y1(n);
double a2 {a[0]}, a1 {a[1]}, a0 {a[2]}, b2 {1.0/a[3]}, b1 {a[4]}, b0 {a[5]};
y[0] = b2*a2*u[0];
y1[1] = T*(a1*u[0] - b1*y[0]);
y[1] = b2*(a2*u[1] + y1[1]);
for(int i=2; i<n; ++i)
{
y0[i] = T*(a0*u[i-2] - b0*y[i-2]) + y0[i-1];
y1[i] = T*(a1*u[i-1] - b1*y[i-1] + y0[i]) + y1[i-1];
y[i] = b2*(a2*u[i] + y1[i]);
}
}
Which works, but the period needs to be very small to get a reasonably good approximation of the continuous function, 0.01, or less, which means the vector will have a considerable size, and can be slow to plot.