Name for programming functions , i think

  • #1
trancefishy
75
0
name for "programming functions", i think...

I'm looking for the name of the class of techniques you use to get functions to do what you want. for example, if you wanted to cycle between odd and even, you would use [tex] -1^n [/tex]. In particular, I want to cycle between 1 and 2, and also be able to output just odd numbers. A couple other things as well, but, this is for a problem I'm working on, and I'd like to just solve it myself. I'm just trying to find a resource that has perhaps a list of little tricks for functions. thanks.
 

Answers and Replies

  • #2
ComputerGeek
383
0
if it is a computer program, why not just have a variable, start at 0, increment by one and every n mod2 ==0 make your cycling variable 2, and when n mod2 == 1, set the variable to 1.

it is not as elegant as a simple mathematical function, but it is a nice solution.

to output just odd numbers, set it up simmilarly, but only output the incremented variable when n mod2 ==1.
 
  • #3
trancefishy
75
0
If my problem were to be solved using a computer, it wouldn't even be a problem, simply an exercise. nope, this needs to be the good ol' f(n) form.

oh, and I've managed to simplify it, i no longer need to cycle 1 and 2 or get only odds, but, I've still got more complicated stuff than that, so, the question still stands.
 
  • #4
ComputerGeek
383
0
oh, well I was confused then because you said "programming" in there.
 
  • #5
jcsd
Science Advisor
Gold Member
2,101
12
[tex]f(n) = \frac{(-1)^n + 3}{2} [/tex]

Cycles between 1 and 2.

Cyclic function is the only name that I can think of for this kind of function.


[tex]f(n) = 2n -1[/tex]

maps the natutral numbers onto the odd numbers.
 
Last edited:

Suggested for: Name for programming functions , i think

Replies
1
Views
283
Replies
2
Views
240
Replies
1
Views
213
  • Last Post
Replies
9
Views
458
  • Last Post
Replies
4
Views
467
Replies
5
Views
382
  • Last Post
Replies
3
Views
382
MHB Functions
  • Last Post
Replies
2
Views
522
Top