Higher accuracy in numerical cumulative integration

roi.holtzman
Fri, 31 Mar 2023 15:08:35 +0000
Numerics

There are some threads about numerical cumulative integration like this and this. However, I have a more basic question.

I am interested in performing the integral S(x; a) = \int_a^x f(x') dx' where x \le b. Note that f(x) is always positive so S(x;a) is monotonically increasing. f(x) has the form f(x) = \sqrt{a_1 - a_2 x^4 + a_3 x^2}.

After I have S(x; a), I want to find x(S; a), namely, I want to invert it.
I understand that I can do the integral numerically for many values of x, and then solve the equation S(x; a) = x_0 to build x(S; a).

Another complication is that the integration limits a, b actually are a function of some other parameter c, but I am guaranteed that S(b(c); a(c)) = \int_{a(c)}^{b(c)} f(x') dx' is always the same value. I mean the total integral is a constant.
That means that I have a bunch of functions S(x; c) that are monotonically increasing from 0 to some fixed value S_0 = S(b(c); a(c)) .
And now I want to invert it.

I am not sure what is the best way to get high accuracy.
I tried the idea by @stevengj that I read here and that is implemented here by @tobydriscoll. I mean, I used ApproxFun to approximate the function f(x), and then to integrate it.

a = 1
b = 2
f_approx = Fun(x->f(x), a..b)
Stmp = integrate(f_approx)
S = Stmp - Stmp(a)

Then I used Newton’s Method to invert the function S(x; a) to x(S;a).
The problem is that for some values of c, I find that the total integral S(b(c); a(c)) = \int_{a(c)}^{b(c)} f(x') dx' gives a smaller value than my initially calculated S_0. This means that I cannot find the root.

Are there any ideas on how to improve this calculation?
Maybe I should use quadgk to calculate the integral instead of ApproxFun?

16 posts - 4 participants