Forgot to attach file. Here it is
#This is a file created by GMatH.
##!
#I have also added this automatic import as a convenience.
#Soon, you will be able to use a Druid to guide you through the import process!
import sys
from Numeric import zeros
from RandomArray import random
CON = 1.4
CON2 = CON*CON
BIG = 1.0e30
SAFE = 2.0
MyError = "The choosen x is too small!"
MyRealError = "The choosen x is not real!"
def Diff(f, x):
global CON, CON2, BIG, SAFE
def func(g, t):
return apply(g, (t,))
if type(x) == type(1.j): raise MyRealError, x
if float(x) == 0.0:
h = random()/1e-10
if float(x) != 0.0:
h = float(x)/10
a = zeros((10,10),'d')
if float(h) == 0.0: raise MyError, x
try:
test = func(f, x)
test = func(f, x+h)
test = func(f, x-h)
except:
print "Is function", str(f), "defined and continous around x =", x,"?"
print sys.exc_type, sys.exc_value
return None
else :
hh = h
a[0][0] = (func(f, x + hh) - func(f, x - hh))/(2.0*hh)
err = BIG
ans = "CANNOT COMPUTE DERIVATIVE"
for i in range(10):
hh = hh/CON
a[0,i] = (func(f, x + hh) - func(f, x - hh))/(2.0*hh)
fac = CON2
for j in range(1, i+1):
a[j][i]=(a[j-1][i]*fac - a[j-1][i-1])/(fac - 1.0)
fac = CON2*fac
errt = max(abs(a[j][i] - a[j-1][i]), abs(a[j][i] - a[j-1][i-1]))
if errt <= err:
err = errt
ans = a[j][i]
if abs(a[i][i] - a[i-1][i-1]) >= SAFE*err:
return ans
return ans
def PDiff(f, var_index, *args):
return 0