Python 2.3.5 (#2, May 4 2005, 08:51:39) [GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2 Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. **************************************************************** IDLE 1.0.5 ==== No Subprocess ==== >>> from polint import polint >>> def f(x): return x*x + x + 1. >>> f(.5) 1.75 >>> xlist = [.1,1.,2.] >>> ylist = [f(x) for x in xlist] >>> ylist [1.1100000000000001, 3.0, 7.0] >>> polint(xlist,ylist,1.) 3.0 >>> polint(xlist,ylist,2.) 7.0 >>> polint(xlist,ylist,1.5) 4.75 >>> f(1.5) 4.75 >>> from math import sin >>> from math import pi >>> xa = [i*pi/10. for i in range(11)] >>> xa [0.0, 0.31415926535897931, 0.62831853071795862, 0.94247779607693793, 1.2566370614359172, 1.5707963267948966, 1.8849555921538759, 2.1991148575128552, 2.5132741228718345, 2.8274333882308138, 3.1415926535897931] >>> ya = [sin(x) for x in xa] >>> ya [0.0, 0.3090169943749474, 0.58778525229247314, 0.80901699437494745, 0.95105651629515353, 1.0, 0.95105651629515364, 0.80901699437494745, 0.58778525229247325, 0.30901699437494751, 1.2246063538223773e-16] >>> def interp(x): return polint(xa,ya,x) >>> interp(.313) 0.30791426011478779 >>> sin(.313) 0.30791426010476708 >>> sin(2.) 0.90929742682568171 >>> interp(2.) 0.9092974268106242 >>> sin(2.*pi) -2.4492127076447545e-16 >>> interp(2.*pi) -0.16720506261921009 >>> from ClimateUtilities import * >>> c = Curve() >>> xplot = [i*pi/10. for i in range(30)] >>> sinplot = [sin(x) for x in xplot] >>> interpplot = [interp(x) for x in xplot] >>> c.addCurve(xplot) >>> c.addCurve(sinplot) >>> c.addCurve(interpplot) >>> plot(c) >>> range(1,0) [] >>> range(1,1) [] >>> >>> >>> import math >>> dumbTrap(math.sin,[0.,math.pi],10) 1.9835235375094544 >>> dumbTrap(math.sin,[0.,math.pi],5) 1.9337655980928052 >>> dumbTrap(math.sin,[0.,math.pi],100) 1.9998355038874436 >>> from ClimateUtilities import * >>> nlist = [2**i for i in range(20)] >>> nlist [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288] >>> Ilist =[] >>> for n in nlist: Ilist.append(dumbTrap(math.sin,[0.,math.pi],n)) >>> ninv = [1./n for n in nlist] >>> ninv [1.0, 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625, 0.0078125, 0.00390625, 0.001953125, 0.0009765625, 0.00048828125, 0.000244140625, 0.0001220703125, 6.103515625e-05, 3.0517578125e-05, 1.52587890625e-05, 7.62939453125e-06, 3.814697265625e-06, 1.9073486328125e-06] >>> c = Curve() >>> c.addCurve(ninv) >>> c.addCurve(Ilist) >>> plot(c) >>> Ilist[-1] 1.9999999999939968 >>> Ilist [1.9236071623538815e-16, 1.5707963267948966, 1.8961188979370398, 1.9742316019455508, 1.9935703437723391, 1.9983933609701447, 1.9995983886400375, 1.9998996001842024, 1.9999749002350522, 1.9999937250705757, 1.9999984312683812, 1.9999996078171405, 1.9999999019542882, 1.9999999754885751, 1.9999999938721471, 1.9999999984680377, 1.9999999996170332, 1.9999999999042506, 1.9999999999760607, 1.9999999999939968] >>> polint(ninv[0:5],Ilist[0:5],0.) 1.999819351662447 >>> polint(ninv[0:6],Ilist[0:6],0.) 2.0000036958197431 >>> polint(ninv[0:7],Ilist[0:7],0.) 1.9999999774847219 >>> n2inv = [x*x for x in ninv] >>> polint(n2inv[0:5],Ilist[0:5],0.) 1.9999999945872897 >>>