def test_neville2d(): funcx = numpy.sin funcy = numpy.exp nrow = 10 ncol = 10 tol = 1.0e-4 # TODO: As with test_neville; can this not be simplified with # vectorized code x = numpy.zeros((nrow, )) y = numpy.zeros((ncol, )) fval = numpy.empty((nrow, ncol)) row_tmp = numpy.pi / nrow # col_tmp = 1.0 / float(ncol) for row in range(nrow): x[row] = (row + 1.0) * row_tmp for col in range(ncol): y[col] = (col + 1.0) / float(ncol) fval[row][col] = funcx(x[row]) * funcy(y[col]) for row in range(ncol): xx = (-0.1 + (row + 1.0) / float(nrow)) * numpy.pi for col in range(4): yy = -0.1 + (col + 1.0) / float(ncol) answer = funcx(xx) * funcy(yy) val = utils.neville2d(xx, yy, x, y, fval) assert utils.Knuth_close(answer, val, tol)
def test_neville(): func = numpy.exp tol = 1.0e-6 num = 10 # TODO: can we not just use vectorized code here? x = [] y = [] for ii in range(num): x.append(ii / float(num)) y.append(func(x[ii])) xx = numpy.array(x) yy = numpy.array(y) for ii in range(num): tmp = 1.01 * (ii / float(num)) answer = func(tmp) val = utils.neville(tmp, xx, yy) assert utils.Knuth_close(answer, val, tol)