/* * Compute power basis coefficients from B-spline basis coefficients */ DenseMatrix getPowerBasisCoefficients(DenseVector c, std::vector<unsigned int> degrees, std::vector<double> lb, std::vector<double> ub) { // Calculate tensor product transformation matrix T*lambda = c DenseMatrix T = getTransformationMatrix(degrees, lb, ub); // Compute power basis coefficients from B-spline basis coefficients DenseMatrix L = T.colPivHouseholderQr().solve(c); return L; }
/* * Transformation matrix taking a power basis to a B-spline basis */ DenseMatrix getTransformationMatrix(std::vector<unsigned int> degrees, std::vector<double> lb, std::vector<double> ub) { unsigned int dim = degrees.size(); assert(dim >= 1); // At least one variable assert(dim == lb.size()); assert(dim == ub.size()); // Calculate tensor product transformation matrix T SparseMatrix T(1,1); T.insert(0,0) = 1; for (unsigned int i = 0; i < dim; i++) { SparseMatrix temp(T); unsigned int deg = degrees.at(i); DenseMatrix Mi = getBSplineToPowerBasisMatrix1D(deg); DenseMatrix Ri = getReparameterizationMatrix1D(deg, lb.at(i), ub.at(i)); DenseMatrix Ti = Mi.colPivHouseholderQr().solve(Ri); T = kroneckerProduct(temp, Ti); } return T; }