I had the opportunity to work on an interesting problem:
Find a decent approximation for the Zeta function (large values), given by:
So, to make any sort of headway, I decided that I would have to look at the graph. Hence, I whipped up a script in Python:
#Author: Shriphani Palakodety
#Mail: shriphani@shriphani.com
#Blog: http://shriphani.com/blog
#Generate the plot of the Zeta function.
from pylab import * #imports the matplotlib graphing library
def zetaValue(n):
”‘Returns the value of the Zeta Function n’”
val = 0
for i in range(1, n+1):
zeta_term = float(1)/float(i**2)
val += zeta_term
return val
def makePlotRange():
”‘Generates an array of form [domain_list, values_list] for 1<1000′”
num_list = [] #This contains the domains
range_list = [] #Contains value returned by Zeta function for every element in domain
for i in xrange(1,1000):
num_list.append(i)
range_list.append(zetaValue(i))
return num_list, range_list
plot_range = makePlotRange() #gets the arrays
plot(plot_range[0], plot_range[1], ‘bs’)
savefig(‘zetaplot.png’)
show()
This looks a like:
Observe this plot. We can see that there is a horizontal asymptote at x = 1.65 .
Hence,
This leads me to conclude one bloody thing:
And,
Now, it shouldn’t come a surprise to all math or CS majors that g(x) is a function whose denominator has a higher degree than the numerator. So for the sake of simplicity, I shall assume that;
Another reason prompting my eagerness to pick that particular function is because of the following observation:
- 1/x is a rectangular hyperbola which looks like:
- If you use -1/x , the graph is rotated about the X axis and it looks like:
- So, if you look at the positive X axis, we have already managed to replicate behavior of the Zeta function. All we need to do is move it up and ensure that the limit stays.
- To move this graph up, just add 1.65 to f(x) and it will work:
- So, the limits match, the behavior matches and all we need to do is test:
#Author: Shriphani Palakodety
#Mail: shriphani@shriphani.com
#Blog: http://shriphani.com/blog
from pylab import * #imports the matplotlib graphing library
def zetaValue(n):
”‘Returns the value of the Zeta Function n’”
val = 0
for i in range(1, n+1):
zeta_term = float(1)/float(i**2)
val += zeta_term
return val
def makePlotRange():
”‘Generates an array of form [domain_list, values_list] for 1<1000′”
num_list = [] #This contains the domains
range_list = [] #Contains value returned by Zeta function for every element in domain
for i in xrange(1,1001):
num_list.append(i)
range_list.append(zetaValue(i))
return num_list, range_list
plot_range = makePlotRange() #gets the arrays
def hypoFunction():
num_list = []
range_list = []
for i in xrange(1, 1001):
num_list.append(i)
range_list.append(float(-1)/float(i) + 1.65)
return num_list, range_list
other_range = hypoFunction()
plot(plot_range[0], plot_range[1], ‘bs’, other_range[0], other_range[1], ‘ro’)
savefig(‘zetaplot.png’)
show()
And this looks like:
Hey, this thing seems to replicate the behavior of the Zeta function way below x=100. Assignment done !!!!
I had another question which is coming up in the next post. I am in love with Discrete math.
Anyway, I attended this job fair thingy and got free stuff from Google, MS and others (MS was giving us ping-pong balls…). Google’s pens are serving me well. Anyway, I am sure I won’t be accepted as an intern anywhere thanks to the fact that every company thinks that freshmen are losers and don’t deserve to be emloyed right in their first year.
Anyway, keep waiting for the second approximation I did.








Your formula doesn’t match your code. One sums k^2, the other 1/k^2.
Python is nice for quick prototypes like this. In fact, your code can still be simplified a bit:
def zetaValue(n):
return sum(1.0/k**2 for k in xrange(1, n+1))
def makePlotRange():
num_list = range(1, 1001)
range_list = map(zetaValue, num_list)
return num_list, range_list
etc.
Thanks for pointing that out. I have corrected the problem.