Ejemplo n.º 1
0
    def test_chebvander3d(self) :
        # also tests chebval3d for non-square coefficient array
        x1, x2, x3 = self.x
        c = np.random.random((2, 3, 4))
        van = cheb.chebvander3d(x1, x2, x3, [1, 2, 3])
        tgt = cheb.chebval3d(x1, x2, x3, c)
        res = np.dot(van, c.flat)
        assert_almost_equal(res, tgt)

        # check shape
        van = cheb.chebvander3d([x1], [x2], [x3], [1, 2, 3])
        assert_(van.shape == (1, 5, 24))
Ejemplo n.º 2
0
    def test_chebvander3d(self):
        # also tests chebval3d for non-square coefficient array
        x1, x2, x3 = self.x
        c = np.random.random((2, 3, 4))
        van = cheb.chebvander3d(x1, x2, x3, [1, 2, 3])
        tgt = cheb.chebval3d(x1, x2, x3, c)
        res = np.dot(van, c.flat)
        assert_almost_equal(res, tgt)

        # check shape
        van = cheb.chebvander3d([x1], [x2], [x3], [1, 2, 3])
        assert_(van.shape == (1, 5, 24))
Ejemplo n.º 3
0
def chebForwardTransform(orders, locations, functionVals):
    if len(locations.shape) == 1:
        return np.array(cheb.chebfit(locations, functionVals, orders[0]))
    else:
        if locations.shape[1] == 2:
            V = cheb.chebvander2d(locations[:, 0], locations[:, 1], orders)
        elif locations.shape[1] == 3:
            V = cheb.chebvander3d(locations[:, 0], locations[:, 1],
                                  locations[:, 2], orders)
        elif locations.shape[1] == 4:
            V = chebVander4d(locations, orders)
        elif locations.shape[1] == 5:
            V = chebVander5d(locations, orders)
        else:
            raise NotImplementedError  # there's a bad startup joke about this being good enough for the paper.
        ret, _, _, _ = npl.lstsq(V, functionVals, rcond=None)
        return np.reshape(ret, (np.array(orders) + 1).flatten())