How can I convert discrete sums to integrals using spline interpolation?

  • Thread starter Thread starter ams2990
  • Start date Start date
  • Tags Tags
    Integrals Sums
ams2990
Messages
11
Reaction score
0
So kind of like this thread, I'm looking to convert a discrete sum to an integral. My idea thus far has been to arrive at a function via spline interpolation. I'm doing a few different types of sums, but the first ones look like

\displaystyle a=\sum_{i=1}^{100}{data[1]<i>*data[4]<i>}</i></i>

where data is of course an two-dimensional array. So I've got a function representing data[1] and a function representing data[4]. I'm not entirely sure what to do from here, primarily because as I increase my sampling "frequency", a is going to balloon. I later do some division by another sum, so the result won't be too different than what I already have, but I'm not really sure how to proceed.
 
Physics news on Phys.org
I am not quite sure what you are doing, but in general to convert a sum to an integral, as you are doing, you need to divide by the number of terms.

Think in terms of the reverse process where an integral is approximated by a sum. Each term in the sum includes a Δx, which is the length of the interval of the integral divided by the number of terms in the sum.
 
mathman said:
I am not quite sure what you are doing, but in general to convert a sum to an integral, as you are doing, you need to divide by the number of terms.

Think in terms of the reverse process where an integral is approximated by a sum. Each term in the sum includes a Δx, which is the length of the interval of the integral divided by the number of terms in the sum.
Example time!
f(i)=5x
g(i)=x^2
\displaystyle \sum_{i=1}^{10}{f(i)g(i)}=15125
\displaystyle \int_{1}^{10}{{f(i)g(i)} di}=12498.8
 
ams2990 said:
Example time!
f(i)=5x
g(i)=x^2
\displaystyle \sum_{i=1}^{10}{f(i)g(i)}=15125
\displaystyle \int_{1}^{10}{{f(i)g(i)} di}=12498.8

A better match would be to use 0.5 and 10.5 as the limits of integration. Since your sum has ten items, the interval for the integral has to be of length 10. The underlying assumption you are using is that Δx = 1. Δx is implicitly multiplying f(i)g(i).

Using the limits I suggest the integral = 15193.75, obviously a lot better.
 
Last edited:
So, I picked an arbitrary example, but in my real problem, I only have data within a certain range (360-830), so while I can theoretically integrate my spline interpolation from 360.5 to 830.5, it's not going to be very reliable past 830. Is there another way?
 
ams2990 said:
So, I picked an arbitrary example, but in my real problem, I only have data within a certain range (360-830), so while I can theoretically integrate my spline interpolation from 360.5 to 830.5, it's not going to be very reliable past 830. Is there another way?
If you want to restrict the domain as you describe, add 1/2 of each of the two end point values to the integral. Going back to your example, you would get 15001.3.
 
This seems to be somewhat violating the spirit of using an integral. It seems we're kind of "hacking on" some Riemann sums to our nice continuous integral in order to get it a little closer to what we'd expect. No?

Also, my final answer via integrals (both with and without those adjustment terms) is significantly different than what I would expect from a "rough" integral (decreasing the step size in the summation and making an educated guess about where they'll end up).
 
ams2990 said:
This seems to be somewhat violating the spirit of using an integral. It seems we're kind of "hacking on" some Riemann sums to our nice continuous integral in order to get it a little closer to what we'd expect. No?

Also, my final answer via integrals (both with and without those adjustment terms) is significantly different than what I would expect from a "rough" integral (decreasing the step size in the summation and making an educated guess about where they'll end up).

I can't comment unless you describe what you did precisely.
 
  • #10
Alright, let's go from example problem to the real problem. No point in coming up with increasingly complex examples.

I've got 6 different spline functions. All are defined on [360, 830]. Let's call them s0, s1, s2, x, y, and z.

From them, I derive some constants:
\displaystyle A_0 = \sum_{i=360}^{830}{s0<i>*x<i>}</i></i>
\displaystyle A_1 = \sum_{i=360}^{830}{s1<i>*x<i>}</i></i>
\displaystyle A_2 = \sum_{i=360}^{830}{s2<i>*x<i>}</i></i>
\displaystyle B_0 = \sum_{i=360}^{830}{s0<i>*y<i>}</i></i>
\displaystyle B_1 = \sum_{i=360}^{830}{s1<i>*y<i>}</i></i>
\displaystyle B_2 = \sum_{i=360}^{830}{s2<i>*y<i>}</i></i>
\displaystyle C_0 = \sum_{i=360}^{830}{s0<i>*z<i>}</i></i>
\displaystyle C_1 = \sum_{i=360}^{830}{s1<i>*z<i>}</i></i>
\displaystyle C_2 = \sum_{i=360}^{830}{s2<i>*z<i>}</i></i>
D_0 = A_0 + B_0 + C_0
D_1 = A_1 + B_1 + C_1
D_2 = A_2 + B_2 + C_2

I then use those with two other constants that I previously calculated to get the two numbers I'm looking for,
M1 = \frac{(B_0 \cdot D_2 - B_2 \cdot D_0) \cdot xD + (A_2 \cdot D_0 - A_0 \cdot D_2) \cdot yD + (A_0 \cdot B_2 - A_2 \cdot B_0)}{(B_2 \cdot D_1 - B_1 \cdot D_2) \cdot xD + (A_1 \cdot D_2 - A_2 \cdot D_1) \cdot yD + (A_2 \cdot B_1 - A_1 \cdot B_2)}
M2 = \frac{(B_1 \cdot D_0 - B_0 \cdot D_1) \cdot xD + (A_0 \cdot D_1 - A_1 \cdot D_0) \cdot yD + (A_1 \cdot B_0 - A_0 \cdot B_1)}{(B_2 \cdot D_1 - B_1 \cdot D_2) \cdot xD + (A_1 \cdot D_2 - A_2 \cdot D_1) \cdot yD + (A_2 \cdot B_1 - A_1 \cdot B_2)}


So initially, I calculated my A0...C2 constants with a step size of 1, so stepping through each function at {360, 361, ..., 829, 830}. Then step sizes of .1, so {360, 360.1, ..., 829.9, 830}. Then step sizes of .01, etc. I felt that doing so will get me progressively closer to the most exact form of the answer, theoretically the form the integral will give me once I work out the quirks. Indeed, I got answers that indicated that M1 and M2 were converging to a certain value.
 
  • #11
From what I can see you are trying to get an integral using the equivalent of the trapezoidal rule. (It was confusing to me previously, since I thought you were trying to do the opposite). For that purpose, I suggest that you modify the sums by using half the values for the two end terms.
 

Similar threads

Back
Top