예제 #1
0
    def mon_mult(self, mon, returnType='Poly'):
        '''
        Multiplies a polynomial by a monomial.

        Parameters
        ----------
        mon : tuple
            The powers in the monomial.
            Ex: x^3*y^4*z^2 would be input as (3,4,2)
        returnType : str
            Which type of object to return.

        Returns
        -------
        MultiPower object if returnType is 'Poly'
        ndarray if returnType is 'Matrix'
        '''
        mon = np.array(mon)
        result = np.zeros(self.shape + mon)
        result[slice_bottom(self.coeff)] = self.coeff
        if returnType == 'Poly':
            return MultiPower(result,
                              clean_zeros=False,
                              lead_term=self.lead_term + mon)
        elif returnType == 'Matrix':
            return result
예제 #2
0
    def _mon_mult1(initial_matrix, idx, dim_mult):
        """
        Executes monomial multiplication in one dimension.

        Parameters
        ----------
        initial_matrix : array_like
            Matrix of coefficients that represent a Chebyshev polynomial.
        idx : tuple of ints
            The index of a monomial of one variable to multiply by initial_matrix.
        dim_mult : int
            The location of the non-zero value in idx.

        Returns
        -------
        ndarray
            Coeff that are the result of the one dimensial monomial multiplication.

        """

        p1 = np.zeros(initial_matrix.shape + idx)
        p1[slice_bottom(initial_matrix)] = initial_matrix

        largest_idx = [i - 1 for i in initial_matrix.shape]
        new_shape = [
            max(i, j)
            for i, j in itertools.zip_longest(largest_idx, idx, fillvalue=0)
        ]  #finds the largest length in each dimmension
        if initial_matrix.shape[dim_mult] <= idx[dim_mult]:
            add_a = [
                i - j for i, j in itertools.zip_longest(
                    new_shape, largest_idx, fillvalue=0)
            ]
            add_a_list = np.zeros((len(new_shape), 2))
            #changes the second column to the values of add_a and add_b.
            add_a_list[:, 1] = add_a
            #uses add_a_list and add_b_list to pad each polynomial appropriately.
            initial_matrix = np.pad(initial_matrix, add_a_list.astype(int),
                                    'constant')

        number_of_dim = initial_matrix.ndim
        shape_of_self = initial_matrix.shape

        #Loop iterates through each dimension of the polynomial and folds in that dimension
        for i in range(number_of_dim):
            if idx[i] != 0:
                initial_matrix = MultiCheb._fold_in_i_dir(
                    initial_matrix, number_of_dim, i, shape_of_self[i], idx[i])
        if p1.shape != initial_matrix.shape:
            idx = [i - j for i, j in zip(p1.shape, initial_matrix.shape)]

            result = np.zeros(np.array(initial_matrix.shape) + idx)
            result[slice_top(initial_matrix)] = initial_matrix
            initial_matrix = result
        Pf = p1 + initial_matrix
        return .5 * Pf