Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I'm trying to find a function. And although it seems to be very simple at first I can't figure it out. Maybe I just need some sleep, and maybe someone could help me out.

given an Integer x between 0 and 100:
if x is between 0-10 then f(x)=0
if x is between 11-20 then f(x)=11
if x is between 21-30 then f(x)=21
if x is between 31-40 then f(x)=31
...
if x is between 91-100 f(x)=91

I'm trying to find the simplest f possible.

The best I could do is:

f(x) = x / 10 * 10

But it's not right.

What function is f?

EDIT

I'm accepting @Didier's solution but I'm going with this one instead.

$$f(x) = \begin{cases} 1+10\lfloor (x-1)/10 \rfloor & \mbox{if } x >10; \\ 0 & \mbox{if } x \leq 10 \end{cases}$$

share|improve this question
    
What language are you using? As I mentioned in comments to the answers, your problem becomes slightly easier if your environment treats 0 and 1 as Booleans... –  J. M. Sep 10 '11 at 18:56
    
I'm on Javascript –  eduardocereto Sep 10 '11 at 19:09
1  
JS, huh? Well then: (x < 11 ? 0 : (10*Math.floor((x-1)/10)+1)) ... –  J. M. Sep 10 '11 at 19:23
    
P.S. generating-functions is for something quite different... –  J. M. Sep 10 '11 at 19:29
add comment

4 Answers

up vote 3 down vote accepted

Let $H$ denote the Heaviside step function, using the convention that $H(x)=1$ if $x\ge0$ and $H(x)=0$ if $x<0$. Then, for every $x$, $$ f(x)=H(x-11)+10\,\sum\limits_{k=1}^9H(x-1-10\,k). $$ An equivalent formulation, based on Iverson bracket, is $$ f(x)=[x\ge11]+10\,\sum\limits_{k=1}^9[x\ge1+10\,k]. $$ Still equivalently, but less rigorously, $$ f(x)=[x\ge11]+10\,[x\ge11]+10\,[x\ge21]+10\,[x\ge31]+\cdots+10\,[x\ge91]. $$

share|improve this answer
    
I have no idea of what you mean. But it looks like cheating to me. A magical function that get's rid of the different range problem. You sure there's no simpler function? –  eduardocereto Sep 10 '11 at 18:46
    
If OP is working in a C-ish language, one could formally replace the unit step functions with Iverson brackets... –  J. M. Sep 10 '11 at 18:48
2  
@eduardo: What's cheating here? Your function is piecewise-defined, and unit step functions are used for representing piecewise-defined functions among other things... –  J. M. Sep 10 '11 at 18:49
    
Sorry I was just checking. I'm not a pro mthematician like you guys. But I'm still trying to understand this function. The $\sum$ is puzzling me. I think I'll go with 2 separate functions, one for the first range and one for the second. –  eduardocereto Sep 10 '11 at 18:54
    
@eduardo: The $\sum$ means you can use a for loop or while loop, as the case may be... –  J. M. Sep 10 '11 at 18:58
show 2 more comments

In C notation,

(x > 10 ? 1 : 0)*((x-1)/10*10 +1)
share|improve this answer
    
Yup, the inline conditional would be best, but I'd have done (x <= 10 ? 0 : 1 + (x-1)/10*10) or something... –  J. M. Sep 10 '11 at 19:03
    
This is very useful, thanks for providing this, I'm accepting Didier's because it's more in line with my question about a single function to solve the case. Though your solution is better in pratical terms to me. –  eduardocereto Sep 10 '11 at 19:10
add comment

The function would be $$f(x)=10\left\lfloor\frac{x-1}{10}\right\rfloor+1$$ where $\lfloor \;\;\;\rfloor$ denotes the floor function, except that the definition for $0\leq x\leq 10$ does not match the pattern of the other parts of the definition - if you defined $f(x)=1$ for $1\leq x\leq 10$ and $f(0)=-9$, then the above function would be correct for all inputs.

share|improve this answer
    
This is exactly what is driving me crazy. The first range doesn't match. But the question is correct. –  eduardocereto Sep 10 '11 at 18:41
2  
If you multiply $f(x)$ with $[x-11 \geq 0]$ where $[p]$ is an Iverson bracket, then his problem's solved. –  J. M. Sep 10 '11 at 18:53
    
I had to google about the Iverson bracket. But it seems good. en.wikipedia.org/wiki/Iverson_bracket –  eduardocereto Sep 10 '11 at 18:56
add comment

$f(x) = 1+10\lfloor (x-1)/10 \rfloor$ works, except for the first range. Are you sure that $f(x)$ is not $1$ for $0 \le x \le 10$?

share|improve this answer
    
yes I'm sure. But thanks for the effort. –  eduardocereto Sep 10 '11 at 18:39
add comment

Your Answer

 
discard

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.