0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ See my edits for proper MathJax usage. $\endgroup$ – Michael Hardy Mar 15 '18 at 15:59
  • $\begingroup$ "If it were to be discretized, there would be losses due to sampling." - recall that an $n$-point Gauss-Legendre quadrature is exact for polynomials of degree $2n-1$ or lower. If your functions are (piecewise) polynomial, you just need to select the right $n$. $\endgroup$ – J. M. is a poor mathematician Mar 31 '18 at 11:08
  • $\begingroup$ @J.M.isnotamathematician I see, then this could be done, select the appropriate number of points, but I really am not a mathematician, I can't see how to calculate the quadrature when it's a function of itself. I'm sorry if I pollute the air with such trivialities. $\endgroup$ – a concerned citizen Mar 31 '18 at 11:14
  • $\begingroup$ I actually find your "recursive" notation quite confusing, due in no small part to your omission of the differential: are you, for example, integrating with respect to $x$ or $y$ in the innermost integral? And what are the bounds? (Gauss-Legendre is for definite integration, with a known integration interval, and not indefinite integration, where the result is an antiderivative.) As an aside: your $f(x)$ is a constant, $\frac{b^2-a^2}{2}$. $\endgroup$ – J. M. is a poor mathematician Mar 31 '18 at 11:17
  • $\begingroup$ In truth, I am in doubt, but I suppose it's $y=f(x)$, that is, a function of the input, which is known at all times. So then, I suppose the integral would be $\int{a*x-b*f(x)\text{d}x}$. And the limits, they would be from T1 to T2, the chosen sampling timings. In the modified question, at the end, I am trying to explain a thought, as childish as it may seem: choose sampling frequency (nr. of points), then apply quadrature between those points. No idea how orthodox it is, but it would have to be a "moving" quadrature, move from sample to sample. Does this mean the order is 2 (=> quad. is 6)? $\endgroup$ – a concerned citizen Mar 31 '18 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.