1
1
#!/usr/bin/env python
4
from scipy_test.testing import *
4
from numpy.testing import *
6
6
from optimize import zeros as cc
9
9
from math import sin,sqrt,log
10
10
from random import random
32
32
elif x < 1 : return -random()
37
36
f2 is a symmetric parabola, x**2 - 1
38
37
f3 is a quartic polynomial with large hump in interval
39
38
f4 is step function with a discontinuity at 1
40
39
f5 is a hyperbola with vertical asymptote at 1
41
f6 has random values positive to left of 1 , negative to right
40
f6 has random values positive to left of 1, negative to right
43
42
of course these are not real problems. They just test how the
44
43
'good' solvers behave in bad circumstances where bisection is
52
51
functions = [f2,f3,f4,f5,f6]
53
52
fstrings = ['f2','f3','f4','f5','f6']
55
from scipy_test.testing import ScipyTestCase
59
54
class test_basic(ScipyTestCase) :
55
def run_test(self, method, name):
58
for function, fname in zip(functions, fstrings):
59
zero, r = method(function, a, b, xtol=0.1e-12, full_output=True)
61
assert_almost_equal(zero, 1.0, decimal=12,
62
err_msg='method %s, function %s' % (name, fname))
66
print 'TESTING CONVERGENCE\n'
67
print 'zero should be 1\n'
68
for i in range(len(functions)) :
69
print 'function %s\n'%fstrings[i]
70
for j in range(len(methods)) :
72
zero = methods[j](functions[i],a,b)
74
print '%s : failed'%mstrings[j]
76
print '%s : %21.16f'%(mstrings[j],zero)
64
def check_bisect(self):
65
self.run_test(cc.bisect, 'bisect')
66
def check_ridder(self):
67
self.run_test(cc.ridder, 'ridder')
68
def check_brentq(self):
69
self.run_test(cc.brentq, 'brentq')
70
def check_brenth(self):
71
self.run_test(cc.brenth, 'brenth')
79
73
def bench_run(self,level=5):
84
print '%s\n',description
86
80
print 'TESTING SPEED\n'
87
81
print 'times in seconds for %d iterations \n'%repeat