# L-31 MCS 260 Wed 7 Nov 2007 : samplefun.py # # Sampling of a function given by the user. from math import * print 'sampling f in [a,b]' e = raw_input('f(x) = ') a = float(input('a = ')) b = float(input('b = ')) N = input('#samples = ') dx = (b-a)/(N+1) x = a S = [] for k in range(0,N): y = eval(e) S.append(y) print 'x = %.4e' % x + \ ' f(x) = %.15e' % y x = x + dx print 'min = %.15e' % min(S) print 'max = %.15e' % max(S)