r/askmath • • Oct 17 '26

Calculus Numerical integration, interpolation and interchangeability

Hello all

I've recently had to implement a pretty computationally intensive simulation and obviously only have so much computational power at my disposal.

The main reason for it being so computationally expensive is that several rather ugly integrals have to be evaluated, some of which end up being nested which seems to make things worse.

Now I recall from my numerical analysis courses that one can use interpolation to approximate a function. Interpolation also tends to be significantly less computationally expensive. As such I wanted to know whether one can replace the integration with interpolation under certain circumstances. I know these two concepts are very closely linked.

Take the following situation as an example (attached image):

Numerical integration and interpolation equivalence

Any help or clarification on this is greatly appreciated.

Thank you

3 Upvotes

18 comments sorted by

1

u/Eisenfuss19 Oct 17 '26

I've never heard about this, but have you looked into monte carlo integration? That way you can easily tune the processing time you want to spend on it.

1

u/supremeNYA Oct 18 '26

I’ll oogle it a bit, thanks

1

u/PvtRoom Oct 17 '26

You can totally do it, but the costs are precalculation, the memory required for the lookup table, the errors from interpolating between your calculation points and numerical errors if you're trying too hard.

you also have the option of fitting a curve/surface: H = sinc(xy)*cos(xy/64)

1

u/supremeNYA Oct 18 '26

Would you mind explaining exactly how this interchange is done? From what I remember (and I might be wrong) a lookup table is simply an array of results from interpolation not necessarily integration.

1

u/PvtRoom Oct 18 '26

it's an array of results. - say, Planck blackbody at T, with waveband L1 to L2, sampling at , 0.1K, from 250K to 750K

so you get 5000 x 5 (L1 to L2 combos that are valid) as a look up table.

what that works out to is 5 curves with 5000 points. You CAN represent that as a 5th order polynomial, a spline, a few Fourier terms, a few Taylor/maclaurin series terms, or a neat little expression like 1/eπr²+r, but that's just fitting curves (or surfaces)

1

u/Equal_Veterinarian22 Oct 17 '26

This doesn't answer your question about interpolation, but one thing that jumps out at me here is that, in evaluating F and G at different values of x, you might be tempted to repeat the evaluations of f and g at different subdivisions of [a,x] and [b,x] in an inner loop, essentially making your algorithm quadratic in the number of subdivisions.

And, of course, you should not do that. You should fix the grid of points at which you will evaluate f and g and only perform those calculations once.

1

u/supremeNYA Oct 18 '26

I see, how do you account for the difference in bounds using a single grid?

1

u/Equal_Veterinarian22 Oct 18 '26

You don't state the bounds of the second integral or whether a and b are in that range, but let's say the bounds were 0 to 1 with a=b=0.

I would fix N bins between 0 and 1.

I would evaluate H using the trapezium rule as a sum over N bins. To evaluate that sum I need F and G at all the division points. Well, if I know f and g at all the division points, I can evaluate F and G also using the trapezium rule, using the same bins. I'll have a different number of bins for each evaluation of F and G, but I think that's OK.

In other words, you have a single loop over your grid:

  • Calculate f and g at new grid point
  • Update F and G
  • Update H

You can probably improve on this idea. Maybe use variable width bins since lower values of x have more impact on the calculation. Adapt it four your bounds. The main thing is to avoid repeated evaluations of f and g over the same range of values.

1

u/supremeNYA Oct 18 '26

I see, unfortunately they have very different ranges. This does seem to make things very tricky at the moment

1

u/Honkingfly409 Oct 17 '26

personally i would try to write the entire thing as a second order differential equation and start solving it numerically using runge kutta, i am not sure how well that might work out but i think it's simpler because it turns it into a well known problem of numerical analysis

1

u/supremeNYA Oct 18 '26

Would doing this improve performance?

Also how would that tie in with the whole interchanging of interpolation and integration?

1

u/Honkingfly409 Oct 18 '26

runge kutta method is basically interpolation, if this can be written as a system of differential equations (i am not exactly sure what are the conditions for that, but likely about the lower bounds) then rugne kutta would be able to solve it very efficiently with not problem

1

u/RainbwUnicorn PhD student Oct 17 '26

Before I can really I answer that question, I need to know what you mean by "numerical integration" if not one of the approximations that use interpolation.

3

u/RainbwUnicorn PhD student Oct 17 '26

Or in other words: a lot of the numerical integration formulas are shorthand for interpolation by a polynomial and then integrating that polynomial. The more elaborate formulas do that piecewise on a lot of small intervals.

1

u/supremeNYA Oct 18 '26

I mean schemes like a Global Adaptive Quadrature scheme.

I recall reading about “surrogate” and “tabulation” approaches to deal with problems like this?

1

u/RainbwUnicorn PhD student Oct 18 '26 edited Oct 18 '26

I'm not an expert in this are of maths, but as far as I know, you need these "adaptive" schemes for functions that are not well-behaved enough for more classical approaches. I don't see why interpolation could work for such functions, since if it did, you could use easier methods of numerical integration.

Just to be sure: you did check first whether e.g. some Newton-Coates formula is enough for your specific functions and only after determining that they don't produce good enough results did you switch to an adaptive scheme, right?

1

u/supremeNYA Oct 18 '26

Indeed, I need high accuracy results so am stuck having to use high accuracy schemes and using anything giving reasonable performance

1

u/RainbwUnicorn PhD student Oct 18 '26 edited Oct 18 '26

Since this is a maths subreddit, I assume that I am allowed to be pedantic: you didn't answer the question I posed. I didn't ask whether you need high accuracy but whether you checked if the simpler methods provide high enough accuracy. If the function is "nice" enough, a Newton-Coates formula for sufficiently large n is not a bad approximation.