Why not evaluate integrals using ODE-solvers? - MathOverflow most recent 30 from http://mathoverflow.net 2013-05-25T16:10:27Z http://mathoverflow.net/feeds/question/47658 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://mathoverflow.net/questions/47658/why-not-evaluate-integrals-using-ode-solvers Why not evaluate integrals using ODE-solvers? Anne 2010-11-29T09:57:55Z 2013-05-21T06:01:32Z <p>Hello!</p> <p>I have a question about the relationship between numerical integration and the solution of ordinary differential equations (ODE). Suppose I want to evaluate the integral $I(x) = \int_{0}^{x} f(t) dt$, where $f$ is a continous function, for some fixed $x = x_{0}$. From the fundamental theorem of calculus I should be able to evaluate this integral by solving an initial value problem $\dot{I} = f(x)$, $I(0) = 0$, $x\in(0,x_{0}]$ right? However, I have seldom seen this method implemented, instead one uses specialized numerical integration codes. How come?</p> <p>Best regards Anne </p> http://mathoverflow.net/questions/47658/why-not-evaluate-integrals-using-ode-solvers/47662#47662 Answer by Ricky Demer for Why not evaluate integrals using ODE-solvers? Ricky Demer 2010-11-29T10:22:14Z 2010-11-29T10:22:14Z <p>They work better. It is usual for the definite integrals we are interested in that don't have a known closed-form solution (eg. <a href="http://en.wikipedia.org/wiki/Elliptic_integral" rel="nofollow">elliptic integrals</a>) to have relatively bad behavior at the endpoints of the interval of integration (eg., discontinuous derivative, infinite derivative, oscillatory), but be very well-behaved on subintervals bounded away from the endpoints (eg. smooth). Because of this, numerical integration codes are designed to pay much more attention to the function near the endpoints than closer to the middle of the interval, which it would be awkward and silly to have an ODE-solver do. Furthermore, numerical integrators can add the summands from smallest to largest, which reduces round-off error as opposed to having to go from left to right, like an ODE-solver.</p> http://mathoverflow.net/questions/47658/why-not-evaluate-integrals-using-ode-solvers/47673#47673 Answer by Jitse Niesen for Why not evaluate integrals using ODE-solvers? Jitse Niesen 2010-11-29T13:03:21Z 2010-11-29T13:03:21Z <p>Your idea is not bad, and there are many connections between the theories of numerical integration and the numerical solutions of ODEs. For instance, the Gauss-Legendre methods for solving ODEs reduces to the Gauss-Legendre method for numerical integration. </p> <p>However, the differential equation $\frac{dI}{dx}=f(x)$ has a special form (the general form is $\frac{dI}{dx}=f(x,I)$) which can be exploited by the methods. Thus, the Gauss-Legendre method for solving ODEs is an implicit method which has to solve an algebraic equation at every step, but this issue disappears when applying it to an ODE of the form $\frac{dI}{dx}=f(x)$. Furthermore, when evaluating an integral numerically, you can split the integration interval in two pieces and add the resulting integrals over the two subintervals. You cannot do the same with an initial-value problem, because the solution over the first subinterval gives you the initial condition for the second subinterval. This means that it's harder to implement adaptive methods for ODEs than for integrals.</p> <p>For these reasons, and the ones mentioned by Ricky Demer, methods written specifically for evaluating integrals perform better than methods for solving ODEs.</p> http://mathoverflow.net/questions/47658/why-not-evaluate-integrals-using-ode-solvers/47676#47676 Answer by Denis Serre for Why not evaluate integrals using ODE-solvers? Denis Serre 2010-11-29T13:55:21Z 2010-11-29T13:55:21Z <p>Once you teach numerical analysis, you reckognize that some problems are related. This is your case: ODEs <em>vs</em> integrals. This is also the case with roots of polynomials <em>vs</em> eigenvalues of matrices (<em>via</em> the companion matrix). It turns out that the naive attitude is generally wrong. For instance, compute the characteristic polynomial first, and then solving the polynomial equation is the wrong way to compute the eigenvalues of a matrix. Instead, we do use the QR method for the eigenvalue problem + the companion matrix, in order to find the roots of a univariate polynomial.</p> <p>The same is true here. We do use numerical methods for the computation of integrals in order to design efficient methods for solving ODEs. Not the converse. This is a matter of stability.</p> http://mathoverflow.net/questions/47658/why-not-evaluate-integrals-using-ode-solvers/47765#47765 Answer by Anne for Why not evaluate integrals using ODE-solvers? Anne 2010-11-30T07:57:12Z 2010-11-30T07:57:12Z <p>Hi,</p> <p>and thank you very much for your answers! As I understand it then, three important advantages of viewing numerical integration (of a continous function) as a special problem (and not as an initial value problem), is that we can</p> <ol> <li>add the summands from smallest to largest to avoid round-off errors,</li> <li>pay more attenation to ends of the integration interval, and</li> <li>split the integration interval into several pieces to ease the construction of adaptive methods.</li> </ol> <p>Best regards, Anne</p> http://mathoverflow.net/questions/47658/why-not-evaluate-integrals-using-ode-solvers/47776#47776 Answer by J. M. for Why not evaluate integrals using ODE-solvers? J. M. 2010-11-30T09:42:14Z 2010-11-30T10:05:53Z <p>Here's my take on the matter: the difference of philosophy between quadrature routines and ODE solving routines, I believe, is this:</p> <blockquote> <p>Extrapolation is riskier than interpolation.</p> </blockquote> <p>Remember that numerical quadrature routines all boil down to approximating your presumably more complicated integrand within the interval of integration with something easier to integrate exactly, and then integrating that. For instance, Newton-Cotes (and in essence, Romberg as well) constructs an interpolating polynomial from your integrand with equispaced abscissas, and integrating that. For Gaussian or Clenshaw-Curtis quadrature, it is equivalent to interpolating your function at "specially spaced" abscissas (Legendre polynomial roots in the former, and Chebyshev polynomial roots in the latter) that have better convergence in the limit. In effect, we run under the assumption that the interpolating function behaves very similarly to the actual integrand within the interval of interest that a sufficient amount of sampling within the integration interval should be enough to capture the behavior of your integrand, and thus give a result hopefully close to the actual value of the integral.</p> <p>In contrast, remember that ODE solvers usually only have initial values to start with. The reason for building in a lot of machinery in current ODE solvers, whether Runge-Kutta, Bulirsch-Stoer, Adams/Gear multistep, or some of the fancier modern techniques, is that <em>extrapolation is inherently unstable</em>. Knowing how the solution looks like in the beginning gives no guarantee how it will behave as the ODE solver marches on; the solution may well be violently oscillatory, or decaying quite fast (so-called "stiff" problems). Thus, there is quite a fair amount of code inscribed in modern ODE solvers for checking how reasonable are the step-sizes being taken, and other such fail-safes.</p> <p>As I did mention in some previous comments, some ODE solving methods are equivalent to quadrature methods when applied to the initial-value problem $y^{\prime}=f(x)$: using classical Runge-Kutta for quadrature is equivalent to performing Simpson's rule, for instance.</p> <p>The point is that ODE solvers tend to be more careful ("tiptoeing", if you will) and thus more effort-intensive than numerical quadrature routines because they make no assumptions on how your integrand behaves. On that note, I will say that you should know that there are integrands (and corresponding intervals) where using an ODE solver might make more sense than using a numerical quadrature routine. One instance that comes to mind: if you know (through graphing, for instance) that your integrand has crazy behavior <em>in a relatively tiny interval within the interval of integration</em>, while the sampling done by a numerical quadrature routine might miss such features (or take a long time to notice them), an ODE solver will be careful to begin with and is less likely to miss the crazy behavior, and will shrink step-sizes as appropriate until it has gone past that interval.</p> http://mathoverflow.net/questions/47658/why-not-evaluate-integrals-using-ode-solvers/131199#131199 Answer by Candyland for Why not evaluate integrals using ODE-solvers? Candyland 2013-05-20T08:11:51Z 2013-05-21T06:01:32Z <p>Yes, integration of ODE involves extrapolation whereas integration of functions involves interpolation. Take for example the Euler's method, we are projecting the slope at the initial point and assume that it applies throughout the time step (which is obviously not the case in general). Worse, the errors accumulate through the time steps. That is, the starting value for the 2nd time step is inaccurate to start with.</p> <p>Integration of functions involves interpolation of a certain polynomial to fit the functional values and evaluating the area under that polynomial. </p> <p>In fact, many researchers have tried to apply functional integration methods to integration of ODEs and not the other way round! We know the Gaussian quadrature is one of the most efficient and accurate numerical integration techniques around. Several ODE solvers are based on the Gauss method - e.g. the fully-implicit Gauss-Legendre method developed by Hollingsworth (1955) and later generalized by Butcher (1964) for arbitrary orders as the Gauss methods (implicit Runge-Kutta processes). </p> <p>Still later, such implicit Runge-Kutta processes are shown to be identical to the collocation methods (Wright, 1970). </p>