#!/usr/bin/env python
# _____________________________
# / ___________________
# / 1 + 2 / ___________ = ?
# |/ |/ 1 + 3 |/ .....
#
#
import math
def get_prev(x, n):
return math.sqrt(1 + n*x)
def eval_first(x0, n):
#print ""
#print "======================"
x = x0
while n > 1:
#print n, x
x = get_prev(x, n)
n -= 1
#print "----------------------"
#print ""
return x
x = 30
for i in range(300):
x = x*x
print x, eval_first(x, 30)
print x, eval_first(x, 100)
C:\Documents and Settings\daewon>sqrt_recurs.py
900 3.00000001286
900 3.0
810000 3.00000003914
810000 3.0
656100000000 3.00000009182
656100000000 3.0
430467210000000000000000 3.00000019735
430467210000000000000000 3.0
185302018885184100000000000000000000000000000000 3.0000004088
185302018885184100000000000000000000000000000000 3.0
34336838202925124846578490892810000000000000000000000000000000000000000000000000
000000000000000 3.00000083251
34336838202925124846578490892810000000000000000000000000000000000000000000000000
000000000000000 3.0
11790184577738583171520872861412518665678211592275841109096961000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000 3.00000168171
11790184577738583171520872861412518665678211592275841109096961000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000 3.0
13900845237714473276493978678966130311421885080852913799160482443003607262976643
59410017691541096095218116655405488994355210000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000
Traceback (most recent call last):
File "C:\Documents and Settings\daewon\sqrt_recurs.py", line 23, in
print x, eval_first(x, 30)
File "C:\Documents and Settings\daewon\sqrt_recurs.py", line 14, in eval_first
그리고, 아마 이렇겠더라.
---
from math import sqrt
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import pprint
def f_god(n, r):
''' .---------------------------------------
f(n, r) = |/ 1 + 2 .------------------------------
|/ 1 + 3 .--------------------
|/ 1 + ... n x r
'''
l = range(2, n+1)
l.reverse()
return reduce(lambda x, y: sqrt(1 + y*x), l, r)
if __name__=="__main__":
r = np.arange(50, 500, 10)
n = np.arange(100, 500, 25)
R, N = np.meshgrid(r, n)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
zs = np.array([f_god(x,y) for x,y in zip(np.ravel(R), np.ravel(N))])
Z = zs.reshape(R.shape)
print Z
ax.plot_surface(R, N, Z)
ax.set_title('Ramanujan equation from god')
ax.set_xlabel('r')
ax.set_ylabel('n')
ax.set_zlabel('result')
plt.show()
'프로그래밍 > Python' 카테고리의 다른 글
TORNADO too many file descriptors in select() (0) | 2015.11.17 |
---|---|
twisted counter 연습문제 (0) | 2015.04.15 |
[PYTHON|PANDAS] pandas.read_csv MemoryError 문제 (0) | 2015.04.01 |
[번역|StackOverflow] 파이썬 람다 - 왜써? / Python Lambda - why? (0) | 2011.10.18 |
[Py] 중복된 숫자 집합을 주어진 합으로 분할하기 (0) | 2009.07.23 |