Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!
tweet

# how to determine the period of a function

By: a guest on Feb 27th, 2012  |  syntax: None  |  size: 0.66 KB  |  views: 21  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. def functionA(origin_matrix,N_times):
2.    #apply rule on the origin_matrix to generate another matrix which is the next sate of it.
3.    #apply rule on origin_matrix for N_times
4.    return the_final_matrix
5.
6. def functionB(origin_matrix):
7.    #determine the period of the the origin_matrix.
8.    return period
9.
10. iterations = 0;
11. tmp = origin_matrix;
12.
13. do
14.     tmp = operation(tmp);
15.     iterations += 1;
16. while tmp != origin_matrix;
17.
18. return iterations;
19.
20. while True:
21.     tmp = operation(tmp)
22.     iterations += 1
23.
24.     if tmp == origin_matrix:
25.         break  # Or you could return here.
26.
27. matrix = origin_matrix
28.
29. for i in range(N_times):
30.     matrix = operation(matrix)
31.
32. return matrix
clone this paste RAW Paste Data
Top