numpy
파이썬에서 고속의 수학 연산을 지원합니다.
http://sourceforge.net/projects/numpy/
SciPy
numpy 를 기반으로 수학이나 과학 문제를 풀 때 쓸만한 유틸리티 모듈입니다. 다양한 인터폴레이션 함수 지원이 매력적입니다.
http://sourceforge.net/projects/scipy/files/
matplotlib
파이썬에서 그래프를 그려주는 모듈입니다.
http://matplotlib.sourceforge.net/
def __newton_subcalc(sx, sy, ex, ey):
return (ey - sy)/float(ex - sx)
def __newton_build(srcList, stack):
"""
x y
1 11
2 12 F[1,2] = (1, 11, 2, 12)
3 13 F[2,3] = (2, 12, 3, 13) F[1,3] = (1, F[1,1], 3, F[2,3])
"""
stack.append((srcList[0][2], srcList[-1][2]))
if len(srcList) <= 1:
return stack
sx, mx, sy = srcList[0]
dstList = []
for mx, ex, ey in srcList[1:]:
v = __newton_subcalc(sx, sy, ex, ey)
dstList.append((sx, ex, v))
sx, sy = mx, ey
return __newton_build(dstList, stack)
def __hermite_build(srcList, stack):
"""
x y
1 11
1 11 F'[1]
2 12 F[1,2] = (1, 11, 2, 12)
2 12 F'[2]
3 13 F[2,3] = (2, 12, 3, 13) F[1,3] = (1, F[1,1], 3, F[2,3])
3 13 F'[3]
"""
stack.append((srcList[0][2], srcList[-1][2]))
if len(srcList) <= 1:
return stack
sx, mx, sy, diff = srcList[0]
dstList = []
dstList.append((sx, sx, diff))
for mx, ex, ey, diff in srcList[1:]:
dstList.append((sx, ex, __newton_subcalc(sx, sy, ex, ey)))
sx, sy = mx, ey
dstList.append((sx, sx, diff))
return __newton_build(dstList, stack)
def hermite_interpolation(srcList, x):
# 재귀함수를 호출할때 사용하는 형식으로 데이터를 바꾼다
srcList = [(cx, cx, cy, diff) for cx, cy, diff in srcList]
stack = __hermite_build(srcList, [])
fc, bc = stack[0]
argList = []
for src in srcList:
argList.append(src[0])
argList.append(src[0])
fc, bc = stack[0]
fr = fc
count = 1
for fc, bc in stack[1:]:
arg = argList[0]
dx = (x - arg)
for arg in argList[1:count]:
dx *= (x - arg)
fr += fc * dx
count += 1
revList = [] + argList
revList.reverse()
fc, bc = stack[0]
br = bc
count = 1
for fc, bc in stack[1:]:
arg = revList[0]
dx = (x - arg)
for arg in revList[1:count]:
dx *= (x - arg)
print "!!", bc*dx
br += bc * dx
count += 1
return fr, br
# x, y, f'(x) 값을 입력합니다.
positions = [
(1.3, 0.6200860, -0.5220232),
(1.6, 0.4554022, -0.5698959),
(1.9, 0.2818186, -0.5811571),
]
print hermite_interpolation(positions, 1.5)


python 을 좋아하는 게임 프로그래머