Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Simple math question

Name: Anonymous 2009-12-15 13:56

Hey /bros/, excuse me while I try to come up with the words to explain this basic math concept. I'm trying to "round" values into steps, like so:

1 2 3 4 5 6 7 8 9

might become

1 1 1 4 4 4 7 7 7

or

1 1 1 1 1 6 6 6 6

I know there's a mathematical operation that can do this. If you were to graph the values, let's say as compared to y = x,  it would look like stairs instead of a straight line. (I'm pretty sure that with the right mathematical function the "step size" could be arbitrary.) I know this must be elementary school-level math and yet nothing is coming to me. Any ideas?

Name: Anonymous 2009-12-16 3:37

Are you working in discrete values or continuous functions? Some algorithms have been proposed so far, but none works for the general case, and they all assume sampled values.

Getting the average of an arbitrary function over an area isn't "elementary school level". What you want is to integrate the function between two bounds a and b, then divide the result by (b-a), which will give you the average. I'll assume that you want your function sampled between the intervals 0-1,2-3,4-5... for simplicity, but your new function can be expressed rather simply as:

f'(x) = integral from (floor x) to (ceil x) of f(x)

In the case of a sampled function, you can use the definition of an integral as a sum of differences and get the equivalent expression. Integral becomes a sum, you'll have to divide by your deltax, and update bounds accordingly.

Your solution in >>10 will work only for the special case of y = x.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List