Changeset 1377 for PythonPackages/DerApproximator
- Timestamp:
- 01/27/2012 12:56:23 PM (4 months ago)
- Files:
-
- PythonPackages/DerApproximator/tests/t1.py (modified) (1 diff)
- PythonPackages/DerApproximator/tests/t_check.py (modified) (1 diff)
- PythonPackages/DerApproximator/tests/t_d2.py (modified) (1 diff)
- PythonPackages/DerApproximator/tests/t_get.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
PythonPackages/DerApproximator/tests/t1.py
r174 r1377 1 1 from DerApproximator import * 2 import numpy as np 3 np.seterr(invalid='ignore') 4 2 5 print get_d1(lambda x: (x**2).sum(), [1,2,3]) 3 6 print get_d1(lambda x: x**2, [1,2,3]) 7 print get_d1(lambda x: ((-x)**0.5)**2, [0], stencil=1) 8 ''' 9 [ 1.99999993 3.99999998 6.0000002 ] 10 [[ 1.99999998 0. 0. ] 11 [ 0. 4.00000006 0. ] 12 [ 0. 0. 6.0000002 ]] 13 [-1.] 14 ''' PythonPackages/DerApproximator/tests/t_check.py
r174 r1377 3 3 4 4 func = lambda x: (x**4).sum() 5 func_d = lambda x: 40 * x**3 5 func_d = lambda x: 40 * x**3 # incorrect; correct: 4 * x**3 6 6 x = arange(1.0, 6.0) 7 r = check_d1(func, func_d, x) 8 ''' 9 func num user-supplied numerical RD 10 0 +4.000e+01 +4.000e+00 3 11 1 +3.200e+02 +3.200e+01 3 12 2 +1.080e+03 +1.080e+02 3 13 3 +2.560e+03 +2.560e+02 3 14 4 +5.000e+03 +5.000e+02 3 15 max(abs(d_user - d_numerical)) = 4500.00002147 16 (is registered in func number 4) 17 *************************************************************************** 18 ''' 7 19 20 func = lambda x: x**4 21 func_d = lambda x: 40 * diag(x**3) # incorrect; correct: 4 * diag(x**3) 22 x = arange(1.0, 6.0) 8 23 r = check_d1(func, func_d, x) 9 10 ###################################### 11 func = lambda x: x**4 12 func_d = lambda x: 40 * diag(x**3) 13 x = arange(1.0, 6.0) 14 15 r = check_d1(func, func_d, x) 16 17 24 ''' 25 func num i,j: dfunc[i]/dx[j] user-supplied numerical RD 26 0 0 / 0 +4.000e+01 +4.000e+00 3 27 6 1 / 1 +3.200e+02 +3.200e+01 3 28 12 2 / 2 +1.080e+03 +1.080e+02 3 29 18 3 / 3 +2.560e+03 +2.560e+02 3 30 24 4 / 4 +5.000e+03 +5.000e+02 3 31 max(abs(d_user - d_numerical)) = 4500.00002147 32 (is registered in func number 24) 33 *************************************************************************** 34 ''' PythonPackages/DerApproximator/tests/t_d2.py
r565 r1377 6 6 7 7 print(get_d2(ff, x)) 8 ''' 9 [[ 2.00000008e+00 7.01739901e-08 9.99999692e-01] 10 [ 7.01774441e-08 1.99999976e+00 -2.80707803e-07] 11 [ 9.99999692e-01 -2.80703855e-07 1.99999994e+00]] 12 ''' PythonPackages/DerApproximator/tests/t_get.py
r174 r1377 4 4 x = arange(1.0, 6.0) 5 5 6 r1 = get_d1(func, x, stencil = 1, diffInt = 1e-5) 7 print(r1) 8 r2 = get_d1(func, x, stencil = 2, diffInt = 1e-5) 9 print(r2) 10 6 r1 = get_d1(func, x, stencil = 1, diffInt = 1e-4) 7 print(r1) # [ 4.00060004 32.00240008 108.00540012 256.00960016 500.0150002 ] 8 r2 = get_d1(func, x, stencil = 2, diffInt = 1e-4) 9 print(r2) # [ 4.00000004 32.00000008 108.00000012 256.00000016 500.0000002 ] 10 r3 = get_d1(func, x, stencil = 3, diffInt = 1e-4) 11 print(r3) # [ 4. 32. 108. 256. 500.]
