//================================================================== Complex Filter::getCoefficient (float gain, Complex* coordinates, int size, int coefficient, int position) { if (coefficient <= 0) return newComplex(gain, 0); if (coefficient > size) return newComplex(0 , 0); return (coordinates[position] * newComplex(-1, 0) * getCoefficient(gain, coordinates, size - 1, coefficient - 1, position + 1) + getCoefficient(gain, coordinates, size - 1, coefficient , position + 1)); }
/* * Main function. * Receives the user input and calls functions to performs the required * operations. */ int main() { //polynomial coefficients a,b,c,d: double a,b,c,d; printf("y(x)=a+b*x+c*x^2+d*x^3\n"); a = getCoefficient('a'); b = getCoefficient('b'); c = getCoefficient('c'); d = getCoefficient('d'); printPolynomial(a,b,c,d); drawGraph(a,b,c,d); return 0; }
float* Filter::getCoefficients (float gain, ComplexVector& coordinates) { int coefficientsSize = (int)coordinates.size() + 1; float* coefficients = new float[coefficientsSize]; for (int i = 0; i < coefficientsSize; i++) coefficients[i] = getCoefficient(gain, coordinates.data(), (int)coordinates.size(), i, 0).real; return coefficients; }
void ReducerHash<Q>::insert(ConstMonoRef multiplier, const Poly& f) { mNodesTmp.clear(); const auto end = f.end(); for (auto it = f.begin(); it != end; ++it) { auto p = mHashTable.insertProduct (it.getMonomial(), multiplier, it.getCoefficient()); if (p.second) mNodesTmp.emplace_back(p.first); } if (!mNodesTmp.empty()) mQueue.push(mNodesTmp.begin(), mNodesTmp.end()); }
int GF256Poly::evaluateAt(int a) { if (a == 0) { return getCoefficient(0); } int size = coefficients.size(); if (a == 1) { // Just the sum of the coefficients int result = 0; for (int i = 0; i < size; i++) { result = GF256::addOrSubtract(result, coefficients[i]); } return result; } int result = coefficients[0]; for (int i = 1; i < size; i++) { result = GF256::addOrSubtract(field.multiply(a, result), coefficients[i]); } return result; }
int checkForSingleConstraint(Constraint* c, int booleanAssignment) { int nonZeroAssignment = booleanAssignment & c->nonZeros; int mask = 1; int i; Numb lhs = 0; for (i = 0; i < c->dim; i++) { if (0 != (mask & nonZeroAssignment)) { lhs += getCoefficient(c, i); } mask = mask << 1; } switch (c->type) { case LESS_EQUAL: return lhs <= c->rhs; case EQUAL: return lhs == c->rhs; default: return lhs >= c->rhs; } return lhs <= c->rhs; }