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

In summary, the conversation discusses converting a sum to an integral using spline interpolation. It is suggested to divide by the number of terms and think in terms of the reverse process, where an integral is approximated by a sum. The conversation then goes into more detail about how to apply this technique in a specific example, using 0.5 and 10.5 as the limits of integration. However, it is noted that this method may not be reliable beyond the given range of data. The conversation also mentions using Riemann sums to improve the accuracy of the integral approximation, but the final results may still differ from a rough integral calculation. The conversation then delves into a real-life problem and the various constants and functions involved in the calculation
  • #1
ams2990
11
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

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

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
  • #2
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.
 
  • #4
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!
[tex]f(i)=5x[/tex]
[tex]g(i)=x^2[/tex]
[tex]\displaystyle \sum_{i=1}^{10}{f(i)g(i)}=15125[/tex]
[tex]\displaystyle \int_{1}^{10}{{f(i)g(i)} di}=12498.8[/tex]
 
  • #5
ams2990 said:
Example time!
[tex]f(i)=5x[/tex]
[tex]g(i)=x^2[/tex]
[tex]\displaystyle \sum_{i=1}^{10}{f(i)g(i)}=15125[/tex]
[tex]\displaystyle \int_{1}^{10}{{f(i)g(i)} di}=12498.8[/tex]

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:
  • #6
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?
 
  • #7
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.
 
  • #8
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).
 
  • #9
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:
[tex]\displaystyle A_0 = \sum_{i=360}^{830}{s0*x}[/tex]
[tex]\displaystyle A_1 = \sum_{i=360}^{830}{s1*x}[/tex]
[tex]\displaystyle A_2 = \sum_{i=360}^{830}{s2*x}[/tex]
[tex]\displaystyle B_0 = \sum_{i=360}^{830}{s0*y}[/tex]
[tex]\displaystyle B_1 = \sum_{i=360}^{830}{s1*y}[/tex]
[tex]\displaystyle B_2 = \sum_{i=360}^{830}{s2*y}[/tex]
[tex]\displaystyle C_0 = \sum_{i=360}^{830}{s0*z}[/tex]
[tex]\displaystyle C_1 = \sum_{i=360}^{830}{s1*z}[/tex]
[tex]\displaystyle C_2 = \sum_{i=360}^{830}{s2*z}[/tex]
[tex]D_0 = A_0 + B_0 + C_0[/tex]
[tex]D_1 = A_1 + B_1 + C_1[/tex]
[tex]D_2 = A_2 + B_2 + C_2[/tex]

I then use those with two other constants that I previously calculated to get the two numbers I'm looking for,
[tex]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)}[/tex]
[tex]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)}[/tex]


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.
 

What is the purpose of converting sums to integrals?

The purpose of converting sums to integrals is to find the area under a curve. This is useful in many scientific fields such as physics, engineering, and mathematics.

What is the difference between a sum and an integral?

A sum is a collection of individual numbers added together, while an integral is a function that represents the area under a curve. Converting a sum to an integral allows for a more accurate representation of the area under the curve.

How do you convert a sum to an integral?

To convert a sum to an integral, you need to take the limit as the number of terms in the sum approaches infinity. This can be done using mathematical techniques such as the Riemann sum or the trapezoidal rule.

What are some applications of converting sums to integrals?

Converting sums to integrals has many applications in science, engineering, and mathematics. Some common examples include finding the distance traveled by an object with varying velocity, calculating the work done by a force, and determining the probability of an event occurring.

Are there any limitations to converting sums to integrals?

While converting sums to integrals can provide more accurate results, there are limitations to this process. It may not be possible to convert certain types of sums to integrals, and the accuracy of the conversion depends on the method used and the number of terms in the sum.

Similar threads

Replies
16
Views
2K
Replies
1
Views
793
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Replies
3
Views
1K
  • Calculus
Replies
2
Views
1K
Replies
4
Views
7K
Replies
8
Views
936
Replies
24
Views
2K
Replies
1
Views
1K
Back
Top