//Main function int main(void){ while(true){ //Loop program forever (unless termination condition reached) //Variables used within function int degree, * coeff; //User interaction printf("Please enter the maximum degree of the polynomial: "); scanf("%d", °ree); //Promt for input if (degree < 0) return 0; //Terminate if negative coefficient given coeff = (int*) calloc(degree + 1, sizeof(int)); printf("Please enter the coefficients: "); readCoefficients(degree, coeff); //Read the coefficients printf("The polynomial is "); printPolynomial(degree, coeff); //Print out the polynomial printf("\n"); printf("Its derivative is "); printDerivative(degree, coeff); //Print out the derivative of the polynomial printf("\n"); printf("\n"); free(coeff); //Deallocate memory used by array to avoid memory leaks } return 0; }
int main(int optionc, char** optionv) { try { /******** * INIT * ********/ // init command line parser util::ProgramOptions::init(optionc, optionv); // init logger logger::LogManager::init(); LOG_USER(logger::out) << "[main] starting..." << std::endl; // read hashes and their coefs std::vector<SegmentHash> hashes = readVariables(optionLabels.as<std::string>()); std::map<SegmentHash, double> coefs = readCoefficients(optionTedCoefficientFile.as<std::string>()); // assemble cost_function.txt std::ofstream costFunctionFile(optionCostFunctionFile.as<std::string>()); double constant = 0; costFunctionFile << "numVar " << hashes.size() << std::endl; for (unsigned int i = 0; i < hashes.size(); i++) { double coef = coefs[hashes[i]]; costFunctionFile << "c" << i << " " << coef << std::endl; if (coef < 0) constant += -coef; } costFunctionFile << "constant " << constant << std::endl; /********* * SETUP * *********/ } catch (Exception& e) { handleException(e, std::cerr); } }
/** reads the objective section */ static SCIP_RETCODE readObjective( SCIP* scip, /**< SCIP data structure */ LPINPUT* lpinput /**< LP reading data */ ) { char name[LP_MAX_LINELEN]; SCIP_VAR** vars; SCIP_Real* coefs; int ncoefs; SCIP_Bool newsection; assert(lpinput != NULL); /* read the objective coefficients */ SCIP_CALL( readCoefficients(scip, lpinput, TRUE, name, &vars, &coefs, &ncoefs, &newsection) ); if( !hasError(lpinput) ) { int i; SCIP_VAR** oldvars; /* set all linear coefficients to 0 */ oldvars = SCIPgetVars(scip); for( i = 0; i < SCIPgetNVars(scip); i++ ) { SCIP_CALL( SCIPchgVarObj(scip, oldvars[i], 0.0) ); } /* set the linear objective values */ for( i = 0; i < ncoefs; ++i ) { SCIP_CALL( SCIPchgVarObj(scip, vars[i], coefs[i]) ); } } /* free memory */ SCIPfreeMemoryArrayNull(scip, &vars); SCIPfreeMemoryArrayNull(scip, &coefs); return SCIP_OKAY; }
void Adafruit_MPL115A2::begin(int sda, int scl) { Wire.begin(sda, scl); // Read factory coefficient values (this only needs to be done once) readCoefficients(); }