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

I need to compare the outputs of some functions and to rate their "erratness".

Given a function, the less erratic function between a and b would be a straight line and the more erratic function would probably be a triangular or sine wave, the bigger its amplitude or its frequency the bigger their erratness. I'm not sure if it's clear what I mean.

I've thought that a way to calculate it could be to calculate the length of the line generated by the function between a and b. The smaller the length the less erratic will be the function.

The questions are:

  1. Do you think this is a good way to achieve what I need?
  2. How can the length of the output of a function be calculated?

Thanks in advance.

share|cite|improve this question
You could look up the arclength integral... – J. M. Apr 14 '12 at 9:21
No idea on what are you talking about :) (I'm not a mathematic) but I will take a look at wikipedia. Thanks! – Ignacio Soler Garcia Apr 14 '12 at 9:29
Right, so type the words "arclength" and "integral" into your favorite search engine, and enjoy. Note that most such integrals do not have nice simple forms, and numerics would be needed. – J. M. Apr 14 '12 at 9:32
Do you mean that they cannot be calculated by an algorithm? I'm developing software. – Ignacio Soler Garcia Apr 14 '12 at 9:38
Stock Trading ... – Ignacio Soler Garcia Apr 14 '12 at 9:52
up vote 3 down vote accepted

There is something called the total variation of a function. If the function is differentiable, it's computed as $\int_a^b|f'(x)|\,dx$. There are standard methods for computing the derivative and the integral numerically. If the function is not differentiable, there's a different definition, which should also be suitable for numerical computation. See the discussion at

share|cite|improve this answer
You rock man. That's what I was looking for and the wiki explanation is great. Thanks again. – Ignacio Soler Garcia Apr 14 '12 at 20:25

If the end-use is an algorithm that must run quickly, your best bet is probably the sum squared difference (or SSD). If the line running between points $a$ and $b$ is: $$ y = mx +n$$ Then you want to sum the squared difference between each point $(x_i,y_i)$ and the line: $$SSD\equiv\sum{(y_i - mx_i -n)^2}$$

The smaller the $SSD$, the less "erratic" your function. Also note that if you have many points and not many computer cycles available, you may want to choose a small random subset of the points instead of summing over all of them.

share|cite|improve this answer
Looks as a good way. I specially like the quadratic feature to penalize more the more erratic points. Thanks, you rock too. – Ignacio Soler Garcia Apr 14 '12 at 20:27

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.