Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In all of the literature that I've found, numerical integration is used to approximate the value of the integral of some function over an interval. I'm trying to do something a little different:

I have a bunch of sampled values coming in at varying, small time steps. At each time step, I want to return the integral of the input for that time step.

So, for each time step, I simply add the new value multiplied by $\Delta t$ to a running total, and return the total for that time step.

This seems to produce the result that I want. However, is this the best way to do this? Without having the entire history of the input, is there a method of integrating that can reduce the error of the output for each time step?

share|cite|improve this question
up vote 1 down vote accepted

If you don't know anything about where the input comes from, you can't do better. If you have a model of the input, you can do better. If you think it is polynomial of degree $n$, you can interpolate the last $n+1$ readings and be there. If you think it is periodic you can do an FFT on your favorite span and get an answer. The quality of your answer is dependent on the quality of your model.

Integration is a low-pass filter. If the function was $1$ for a long time, the integral becomes large, so you need to say you are returning the integral since some time.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.