arma::vec polynomial( const arma::vec& parameter, const arma::uword highestDegree) { if (parameter.n_elem == 0 || highestDegree == 0) { // By definition, the constant term is 1. return {1.0}; } arma::vec polynomial(polynomialSize(parameter.n_elem, highestDegree)); arma::uword n = 0; // Generates all terms for degree > 1 for (arma::uword degree = highestDegree; degree >= 2; --degree) { for (const auto& multicombination : multicombinations(parameter.n_elem, degree)) { const arma::vec& partialParameter = parameter.elem(multicombination); polynomial(n++) = arma::prod(partialParameter); } } // Linear term polynomial.subvec(n, n + parameter.n_elem - 1) = parameter; // By definition, the constant term is 1. polynomial(polynomial.n_elem - 1) = 1; return polynomial; }
//***************************************************************************** // METHOD: ossimRpcProjection::worldToLineSample() // // Overrides base class implementation. Directly computes line-sample from // the polynomials. //***************************************************************************** void ossimRpcProjection::worldToLineSample(const ossimGpt& ground_point, ossimDpt& imgPt) const { if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimRpcProjection::worldToLineSample(): entering..." << std::endl; if(ground_point.isLatNan() || ground_point.isLonNan() ) { imgPt.makeNan(); return; } //* // Normalize the lat, lon, hgt: //* double nlat = (ground_point.lat - theLatOffset) / theLatScale; double nlon = (ground_point.lon - theLonOffset) / theLonScale; double nhgt; if(ossim::isnan(ground_point.hgt)) { nhgt = (theHgtScale - theHgtOffset) / theHgtScale; } else { nhgt = (ground_point.hgt - theHgtOffset) / theHgtScale; } //*** // Compute the adjusted, normalized line (U) and sample (V): //*** double Pu = polynomial(nlat, nlon, nhgt, theLineNumCoef); double Qu = polynomial(nlat, nlon, nhgt, theLineDenCoef); double Pv = polynomial(nlat, nlon, nhgt, theSampNumCoef); double Qv = polynomial(nlat, nlon, nhgt, theSampDenCoef); double U_rot = Pu / Qu; double V_rot = Pv / Qv; //*** // U, V are normalized quantities. Need now to establish the image file // line and sample. First, back out the adjustable parameter effects // starting with rotation: //*** double U = U_rot*theCosMapRot + V_rot*theSinMapRot; double V = V_rot*theCosMapRot - U_rot*theSinMapRot; //*** // Now back out skew, scale, and offset adjustments: //*** imgPt.line = U*(theLineScale+theIntrackScale) + theLineOffset + theIntrackOffset; imgPt.samp = V*(theSampScale+theCrtrackScale) + theSampOffset + theCrtrackOffset; if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimRpcProjection::worldToLineSample(): returning..." << std::endl; return; }
int main(int argc, char *argv[]) { const int test_size = 4096 * 2; std::normal_distribution<float> dist(0.5f, 0.5f); rng.seed(0); float *r_values = nullptr; float *ret = nullptr; float *ret2 = nullptr; double sum = 0.0f; std::function<float()> rnd = std::bind(dist, rng); r_values = static_cast<float*>(_mm_malloc(sizeof(float) * test_size, 32)); ret = static_cast<float*>(_mm_malloc(sizeof(float) * test_size, 32)); ret2 = static_cast<float*>(_mm_malloc(sizeof(float) * test_size, 32)); if (!(r_values && ret && ret2)) goto exit; std::generate_n(r_values, test_size, rnd); for (int i = 0; i < 100000; ++i) { polynomial(ret, r_values, test_size); // polynomial(ret2, ret, test_size); sum = std::accumulate(ret, ret + test_size, sum); } std::cout << sum << std::endl; exit: _mm_free(r_values); _mm_free(ret); _mm_free(ret2); }
int main(void) { /*Repeating the main function*/ while (1) { int i; /*User input 1*/ printf("Please enter the maximum degree of the polynomial: "); scanf("%d", &max); a = (int*) calloc(max+1, sizeof(int)); /*Terminate if a negative number*/ if(max < 0) { return 0; } /*User input 2*/ printf("Please enter the coefficients: "); /*Input max+1 numbers*/ for (i=0; i <= max; i++) { scanf("%d", &a[i]); } power = max; polynomial(); power = max; derivative(); free(a); } }
int main(void) { int degree; //there will be a valiable called degree that will be an integor int a[10]; //creates an array, a, and assigns 10 values that are integors int i; //there will be an variable called i that will be an integor degree=1; while(degree>0) { printf("Please enter the maximum degree of the polynomial: "); //asks user to imput the degree of polynomial scanf("%d", °ree); if(degree<0) { return 0; } printf("Please enter the coefficients: "); //asks user to imput the coefficients for(i=0; i<=degree; i++) //creates a loop that repeats untill the array number is equal to the degree scanf("%d", &a[i]); //calls the coefficients of the array printf("The polynomial is "); polynomial(a, degree); //calls function polynomial printf("\nIts derivative is "); calculatederivative(a, degree); printf("\n\n"); } }
int main(void) { while(1) // the program will anew as long as this loop remains true { int deg; // degree int i; int * coeff; // array to store the coefficients as input by the user printf("Please enter the maximum degree of the polynomial: "); scanf("%d", °); coeff = (int*)calloc(deg+1, sizeof(int)); if(deg >= 0) // check and carry out actions only if input is correct (degree is positive) { printf("Please enter the coefficients: "); for(i=0; i<=deg ;i++) // allow the user to input coefficients as many times as required scanf("%d", &coeff[i]); printf("The polynomial is "); polynomial(coeff, deg); // send the stored information to polynomial funtion printf("\n"); printf("Its derivative is "); derivative(coeff, deg); // send the stored information to derivative function printf("\n\n"); free(coeff); // always free the memory for next usage after anewing the program } else break; // breaks the operation, and hence terminates the program } return 0; }
bool ArModel::check_stationary(const Vec &phi){ // The process is stationary if the roots of the polynomial // // 1 - phi[0]*z - ... - phi[p-1]*z^p. // // all lie outside the unit circle. We can do that by explicitly // finding and checking the roots, but that's kind of expensive. // Before doing that we can do a quick check to see if the // coefficients are within a loose bound. // // Based on Rouche's theorem: // http://en.wikipedia.org/wiki/Properties_of_polynomial_roots#Based_on_the_Rouch.C3.A9_theorem // All the roots will be at least 1 in absolute value as long as // sum(abs(phi)) < 1. if(phi.abs_norm() < 1) return true; // If that didn't work then we're stuck finding roots. // TODO(stevescott): Really we just need to check the smallest // root. If we had a cheap way of finding just the smallest root // then that would be more efficient than finding them all. Vector coefficients = concat(1, -1 * phi); Polynomial polynomial(coefficients); std::vector<std::complex<double> > roots(polynomial.roots()); for (int i = 0; i < roots.size(); ++i) { if (abs(roots[i]) <= 1) return false; } return true; }
int main(){ int question; printf("This is ece177 lab2 solving 4 questions.\nPlease enter\n1 for temperature,\n2 for polynomial,\n3 for solution,\n4 for freefalldistance.\n0 for exit.\n"); scanf("%d",&question); while(question!=0){ switch (question){ case 1: temperature(); break; case 2: polynomial(); break; case 3: solution(); break; case 4: freefalldistance(); break; default: printf("Sorry, your choice did not match any of the four. Please try again.\n"); break; } printf("This is ece177 lab2 solving 4 questions.\nPlease enter\n1 for temperature,\n2 for polynomial,\n3 for solution,\n4 for freefalldistance.\n0 for exit.\n"); scanf("%d",&question); } return 0; }
double zonal_pressure(double rho_value, double theta_value) { /* printf("Zonal Pressure %lf %lf\n", rho_value, theta_value); */ return(polynomial(p_poly, 2, rho_table, theta_table, rho_value, theta_value)); }
double zonal_energy(double rho_value, double theta_value) { /* printf("Zonal Energy %lf %lf\n", rho_value, theta_value); */ return(polynomial(e_poly, 2, rho_table, theta_table, rho_value, theta_value)); }
void deriv708a (const range &r, char *task, char answ[][BUFSZ], char *src) { char buf[20][BUFSZ]; int a, b, p, c; do { a = rndr(r); b = rndr(r); p = rndr(r); c = rndr(r); } while (!(a>0 && b>0)); char ax2b[BUFSZ]; polynomial(ax2b,2, a,"x^2", b,""); char lnax2b[BUFSZ]; sprintf(lnax2b, "ln(%s)", ax2b); strcpy(task, ""); catprintf(task, "String(\"Найдите производную указанной функции:\")"); catprintf(task, "\ny(x)=((%s)/sqrt(%s))*cos(%d)", polynomial(buf[0],2, 1,lnax2b, c,""), ax2b, p ); sprintf(src, "y(x)=((ln(a*x^2+b)+c)/sqrt(a*x^2+b))*cos(p)"); sprintf(answ[0], "y(x)`=((%s)/sqrt((%s)^3))*cos(%d)", polynomial(buf[0],1, a,chprintf(buf[1],"x*(%s)", polynomial(buf[2],2, 2-c,"", -1,lnax2b))), ax2b, p ); sprintf(answ[1], "y(x)`=((%s)/sqrt((%s)^3))*cos(%d)", polynomial(buf[0],1, a,chprintf(buf[1],"x^2*(%s)", polynomial(buf[2],2, 1-c,"", -1,lnax2b))), ax2b, p ); sprintf(answ[2], "y(x)`=((%s)/sqrt((%s)^3))*sin(%d)", polynomial(buf[0],1, a,chprintf(buf[1],"x*(%s)", polynomial(buf[2],2, c-2,"", 1,lnax2b))), ax2b, p ); sprintf(answ[3], "y(x)`=((%s)/(%s))*sin(%d)", polynomial(buf[0],1, a,chprintf(buf[1],"x^2*(%s)", polynomial(buf[2],2, 1,lnax2b, -2+c,""))), ax2b, p ); }
int main (void) { int i,j; int power; printf("Please enter the maximum degree of polynomial: "); scanf("%d", °ree); if (degree<0) { exit(0); } /* Enter the coefficient */ printf("\nPlease enter the coefficient: "); for (i = 0; i<= degree; i++) { scanf("%d",&coefficient[i]); } /* Print the polynomial */ power = degree; printf("\nThe polynomial is"); for (i = 0; i <= degree; i++) { printf(" %d ", coefficient[i]); polynomial(power); /* Print the degree */ power--; } /* Print the reciprocal */ power = degree; j = i; printf("\nThe reciprocal is"); for (j = degree; j >= 0; j--) { printf(" %d", coefficient[j]); polynomial(power); /* Print the degree */ power--; } check_equality(i,j); return 0; }
void deriv413a (const range &r, char *task, char answ[][BUFSZ], char *src) { char buf[20][BUFSZ]; int a, b, c; do { a = rndr(r); b = rndr(r); c = rndr(r); } while (!(a>1 && b!=0)); strcpy(task, ""); catprintf(task, "String(\"Найдите производную указанной функции:\")"); catprintf(task, "\ny(x)=sin(log(%d,%s))+cos(%d)", a,polynomial(buf[0],1,b,"x"),c); sprintf(answ[0], "y(x)`=cos(log(%d,%d))/(x*ln(%d))",a,b,a); sprintf(answ[1], "y(x)`=(cos(log(%d,%d))/((%s)*ln(%d)))+sin(%d)",a,b,polynomial(buf[0],1,b,"x"),a,c); sprintf(answ[2], "y(x)`=%s", polynomial(buf[0],1,b,chprintf(buf[1],"cos(1/((%s)*ln(%d)))", polynomial(buf[2],1,b,"x"),a))); sprintf(answ[3], "y(x)`=(cos(log(%d,%d))/(x*ln(%d)))-sin(%d)", a,b,a,c); }
void deriv415a (const range &r, char *task, char answ[][BUFSZ], char *src) { char buf[20][BUFSZ]; int a, b, c; do { a = rndr(r); b = rndr(r); c = rndr(r); } while (!(a>1 && b>0)); strcpy(task, ""); catprintf(task, "String(\"Найдите производную указанной функции:\")"); catprintf(task, "\ny(x)=arcsin(sqrt(%d/x))+arctg(%d)", b,c); sprintf(answ[0], "y(x)`=-(%s/(2*x*sqrt(%s)))",fraction(buf[0],1,b,1),polynomial(buf[1],2,1,"x",-b,"")); sprintf(answ[1], "y(x)`=(%s)/(2*sqrt(%s))",polynomial(buf[0],1,b,"x"),polynomial(buf[1],2,1,"x",-b,"")); sprintf(answ[2], "y(x)`=(%d)/(2*x^2*sqrt(1-(%d)/x))+arctg(%d)",-b,b,c); sprintf(answ[0], "y(x)`=-(%s/(2*x*sqrt(%s)))+(%s)",fraction(buf[0],1,b,1),polynomial(buf[1],2,1,"x",-b,""), fraction(buf[2],1,1,1+c*c)); }
int main(void) { /*Intialising the variables*/ int degree; int coefficient[11]; int i; void polynomial(int degree, int coefficient[11]); do { /*Asking the user to input values for the polynomial*/ printf("Please enter the maximum degree of the polynomial: "); scanf("%d", °ree); /*This while loop checks if the degree is below 0 i.e minus and terminates the program if its true*/ while(degree<0) { return 0; } /*Asking the user to input the coefficients*/ printf("Please enter the coefficients: "); for (i=0; i <= degree; i++) { /*This for loop repeats the scanf the required number of times depending on the input of the degree*/ scanf("%d", &coefficient[i]); } /*The results of the program*/ printf("The polynomial is "); polynomial(degree, coefficient); printf("\n"); printf("The reciprocal is "); reciprocal(degree, coefficient); printf("\n"); /*Checks whether the polynomial is self-reciprocal and prints the result*/ if(selfreciprocal(degree, coefficient)==1) printf("The polynomial is self-reciprocal \n"); if(selfreciprocal(degree, coefficient)==0) printf("The polynomial is not self-reciprocal \n"); printf("\n\n"); } while(selfreciprocal(degree, coefficient)==0); /*Will terminate the loop if the polynomial is self-reciprocal*/ return 0; }
int main(void) { int degree; //there will be a valiable called degree that will be an integor int a[10]; //creates an array, a, and assigns 10 values that are integors int i; //there will be an variable called i that will be an integor int j; //there will be a variable called j that will be an integor degree=1; while(degree>0) { printf("Please enter the maximum degree of the polynomial: "); //asks user to imput the degree of polynomial scanf("%d", °ree); if(degree<0) { return 0; } printf("Please enter the coefficients: "); //asks user to imput the coefficients for(i=0; i<=degree; i++) //creates a loop that repeats untill the array number is equal to the degree scanf("%d", &a[i]); //calls the coefficients of the array printf("The polynomial is: "); polynomial(a, degree); //calls function polynomial printf("\nThe reciprocal is: "); reciprical(a, degree); //calls function reciprical int isreciprocal = 1; //ture j=degree; for(i=0; i<= degree; i++) { if(a[i] != a[j]) isreciprocal = 0; j--; } if(isreciprocal == 1) { printf("\nThe polynomial is self-reciprocal"); } else { printf("\nThe polynomial is not self-reciprocal"); } printf("\n\n"); } }
void deriv414a (const range &r, char *task, char answ[][BUFSZ], char *src) { char buf[20][BUFSZ]; int a, b, c; do { a = rndr(r); b = rndr(r); c = rndr(r); } while (!(a>1 && b!=0)); strcpy(task, ""); catprintf(task, "String(\"Найдите производную указанной функции:\")"); catprintf(task, "\ny(x)=cos((%d)^(%s))^2+tg(%d)", a,polynomial(buf[0],1,b,"x"),c); char blna[BUFSZ]; polynomial(blna,1, b,chprintf(buf[0],"ln(%d)",a)); char abx[BUFSZ]; sprintf(abx,"(%d)^(%s)", a, polynomial(buf[0],1,b,"x")); sprintf(answ[0], "y(x)`=(-sin(2*%s))*.(%s)*.(%s)",abx,abx,blna); sprintf(answ[1], "y(x)`=2*(cos(%s))*.(%s)+tg(%d)",abx,blna,c); sprintf(answ[2], "y(x)`=(sin(%s)^2)*.(%s)+1/cos(%d)^2",abx,blna,c); sprintf(answ[3], "y(x)`=2*(cos(%s))*.(sin(%s)^2)*.(%s)",abx,abx,blna); }
void deriv412a (const range &r, char *task, char answ[][BUFSZ], char *src) { char buf[20][BUFSZ]; int a, b, c; do { a = rndr(r); b = rndr(r); c = rndr(r); } while (!(a>1 && b!=0)); char bx[BUFSZ]; polynomial(bx,1, b,"x"); strcpy(task, ""); catprintf(task, "String(\"Найдите производную указанной функции:\")"); catprintf(task, "\ny(x)=(%d)^arctg(%s)+tg(%d)^2", a,bx,c); sprintf(src, "y(x)=a^arctg(b*x)+tg(c)^2"); sprintf(answ[0], "y(x)`=(%d)^arctg(%s)*.!(ln(%d))*.(%d/(%s))", a,bx,a,b,polynomial(buf[0],2,1,"",b*b,"x^2")); sprintf(answ[1], "y(x)`=(%d)^arctg(%s)*.!(ln(%d))+tg(%d)^2", a,bx,a,c); sprintf(answ[2], "y(x)`=(%d)^(%d/(%s))*.!(ln(%d))+(2*tg(%d))/(cos(%d)^2)", a,b,polynomial(buf[0],2,1,"",b*b,"x^2"),a,c,c); sprintf(answ[3], "y(x)`=arctg(%s)*(%d)^(arctg(%s)-1)*.(%d/(%s))", bx,a,bx,b,polynomial(buf[0],2,1,"",b*b,"x^2")); }
void deriv409a (const range &r, char *task, char answ[][BUFSZ], char *src) { char buf[20][BUFSZ]; int a, b, c; do { a = rndr(r); b = rndr(r); c = rndr(r); } while (!(a>1 && b!=0 && c>1)); char bx[BUFSZ]; polynomial(bx,1, b,"x"); strcpy(task, ""); catprintf(task, "String(\"Найдите производную указанной функции:\")"); catprintf(task, "\ny(x)=(%d)^tg(%s)+1/ln(%d)", a,bx,c); sprintf(src, "y(x)=a^tg(b*x)+1/ln(c)"); sprintf(answ[0], "y(x)`=(%d)^tg(%s)*.(%d/cos(%s)^2)*.ln(%d)", a,bx,b,bx,a); sprintf(answ[1], "y(x)`=(%d)^tg(%s)*.(%d/sin(%s)^2)*.ln(%d)", a,bx,-b,bx,a); sprintf(answ[2], "y(x)`=(%d)^tg(%s)*.(%d/cos(%s)^2)-1/(%s)", a,bx,b,bx,polynomial(buf[0],1,c,chprintf(buf[1],"ln(%d)^2",c))); sprintf(answ[3], "y(x)`=tg(%s)*.(%d)^(tg(%s)-1)*.(1/cos(%s)^2)+1/ln(%d)", bx, a, bx, bx, c); }
float getRoots(float possibleRoots[],int possibleRootCounter) { int j=0; for (int i=0;i<possibleRootCounter;i++) { if (polynomial((float)possibleRoots[i]) == 0) { Roots[j++]=possibleRoots[i]; printf("Roots[%d]=%f\n",j-1,Roots[j-1]); rootsCounter++; } } return rootsCounter; }
void deriv706a (const range &r, char *task, char answ[][BUFSZ], char *src) { char buf[20][BUFSZ]; int a, n; do { a = rndr(r); n = rndr(r); } while (!(a!=0 && n>0)); strcpy(task, ""); catprintf(task, "String(\"Найдите производную указанной функции:\")"); catprintf(task, "\ny(x)=arctg(%s)/(%s)", memb(buf[0], 1,a,1,1,"x", false), memb(buf[1], 1,1,n,1, polynomial(buf[2],2, a*a,"",1,"x^2"), false) ); sprintf(src, "y(x)=arctg(x/a)/(a^2+x^2)^n"); char xarctg[BUFSZ]; sprintf(xarctg, "x*arctg(%s)", memb(buf[0], 1,a,1,1, "x", false)); sprintf(answ[0], "y(x)`=(%s)/(%s)", polynomial(buf[0],2, a,"", -2*n,xarctg), memb(buf[1], 1,1,n+1,1, polynomial(buf[2],2, a*a,"", 1,"x^2"), false) ); sprintf(answ[1], "y(x)`=(%s)/(%s)", polynomial(buf[0],2, a*a,"", -4*n,xarctg), memb(buf[1], 1,1,n+1,1, polynomial(buf[2],2, a*a,"", 1,"x^2"), false) ); sprintf(answ[2], "y(x)`=(%s)/(%s)", polynomial(buf[0],2, a,polynomial(buf[1],2, a*a,"", 1,"x^2"), -2*n,xarctg), memb(buf[2], 1,1,n,1, polynomial(buf[3],2, a*a,"", 1,"x^2"), false) ); sprintf(answ[3], "y(x)`=(%s)/(%s)", polynomial(buf[0],2, a*a,"", -2*n,xarctg), memb(buf[1], 1,1,n,1, polynomial(buf[2],2, a*a,"", 1,"x^2"), false) ); }
int main() { while(1){ int i; /* Give values to array by the order of i*/ int co[11]; /* The array to store the coefficients of polynomial*/ int n; /* The maximum degree of polynomial*/ int k=0; /* The variable to check reprocical*/ /* Prompt the user for maximum degree */ printf("Please enter the maximum degree of the polynomial:"); scanf("%d", &n); /* Check whether the maximum degree is negative number If so, terminate here. Otherwise continue the program*/ if(n<0){ return 0;} else{ printf("Please enter the coefficients:"); for(i=0;i<=n;i++){ scanf("%d", &co[i]);} /* Print two polynomials*/ polynomial(n,co); reciprocal(n,co); /* Check whether it is self-reciprocal or not.If coefficient is equal to that after changingposition, K will get 1 increment. Otherwise 0 increment. If k=n+1, that means p(x) = p*(x) and terminate the program*/ for(i=0;i<=n;i++){ if(co[i]==co[n-i]){ k = k+1;} else{k = k;}} if(k==(n+1)){ printf("The polynomial is self-reciprocal\n"); return 0;} else{ printf("The polynomial is not self-reciprocal\n"); printf("\n"); } } } }
int main(void){ int coefficient[SIZE]; int K, N, Power; int count3 = 0; /* Below while loop basically creat repeatatinon of Entering the polynomial */ N=1; while (N>0){ /* asking the user to the maximum degree of polynomai, which is then taken by scanf*/ printf("Please enter the maximum degree of the polynomial:"); scanf("%d", &N); if(N<0){ exit(0); } /*asking the user the input the coeff*/ printf("Please enter the coefficients:"); for(K=0; K<=N; K++) { scanf("%d", &coefficient[K]); } Power = N; /*Here the functions are called in the main*/ polynomial(coefficient, Power, N); reciprocal(coefficient, Power , N); printf("\n"); } exit(0); }
void deriv707a (const range &r, char *task, char answ[][BUFSZ], char *src) { char buf[20][BUFSZ]; int a, b, c; do { a = rndr(r); b = rndr(r); c = rndr(r); } while (!(a!=0 && b>1)); char arctgxac[BUFSZ]; polynomial(arctgxac,2, 1,chprintf(buf[0],"arctg(%s)", memb(buf[1], 1,a,1,1, "x", false)), c,"" ); char xarctgxac[BUFSZ]; sprintf(xarctgxac, "x*(%s)", arctgxac); char a2x2[BUFSZ]; polynomial(a2x2,2, a*a,"",1,"x^2"); strcpy(task, ""); catprintf(task, "String(\"Найдите производную указанной функции:\")"); catprintf(task, "\ny(x)=((%s)/sqrt(%s))*ln(%d)", arctgxac, a2x2, b); sprintf(src, "y(x)=((arctg(x/a)+c)/sqrt(a*x^2+b))*ln(b)"); sprintf(answ[0], "y(x)`=((%s)/sqrt((%s)^3))*ln(%d)", polynomial(buf[0],2, a,"", -1,xarctgxac), a2x2, b ); sprintf(answ[1], "y(x)`=((%s)/sqrt((%s)^3))*ln(%d)", polynomial(buf[0],2, a,"", -2,xarctgxac), a2x2, b ); sprintf(answ[2], "y(x)`=((%s)/(%s))*ln(%d)", polynomial(buf[0],2, a,"", -1,xarctgxac), a2x2, b ); sprintf(answ[3], "y(x)`=((%s)/(%s))", polynomial(buf[0],2, a,"", -1,xarctgxac), polynomial(buf[1],1, b,a2x2) ); }
// Check for identically zero polynomials using randomized polynomial identity testing template<class R,class PerturbedT> static void assert_last_nonzero(void(*const polynomial)(R,RawArray<const Vector<Exact<1>,PerturbedT::m>>), R result, RawArray<const PerturbedT> X, const char* message) { typedef Vector<Exact<1>,PerturbedT::m> EV; const int n = X.size(); const auto Z = GEODE_RAW_ALLOCA(n,EV); for (const int k : range(20)) { for (int i=0;i<n;i++) Z[i] = EV(perturbation<PerturbedT::m>(k<<10,X[i].seed())); polynomial(result,Z); if (last_nonzero(result)) // Even a single nonzero means we're all good return; } // If we reach this point, the chance of a nonzero nonmalicious polynomial is something like (1e-5)^20 = 1e-100. Thus, we can safely assume that for the lifetime // of this code, we will never treat a nonzero polynomial as zero. If this comes up, we can easily bump the threshold a bit further. throw AssertionError(format("%s (there is likely a bug in the calling code), X = %s",message,str(X))); }
int main(void) {/*Declaring variables*/ int b; int degree; int coefficient[11]; int reciprocal1[11]; do/*Allows the program loop*/ { printf("Please enter the maximum degree of the polynomial :");/*prompting user for input of maximum degree*/ scanf("%d" , °ree); /*makes the program terminate when a negative integer is inputed*/ if(degree<0) { return 0; } printf("Please enter the coefficients:");/*prompting user for input of coefficients*/ for (b=0; b <= degree; b++)/*A for loop that repeats scanf the required number of times depending on the degree of the polynomoial*/ { scanf("%d", &coefficient[b]); } printf("The polynomial is ");/*printing the polynomial*/ polynomial(degree,coefficient); printf("Its reciprocal is ");/*Printitng the Reciprocal*/ reciprocal(degree,coefficient); /*Determining if the polynomial is self reciprocal or not*/ if (determination(b, degree, reciprocal1, coefficient)==1) { printf("This not self reciprocal \n\n"); } if (determination(b, degree, reciprocal1, coefficient)==0) { printf("This is self reciprocal \n\n"); } } while (determination(b, degree, reciprocal1, coefficient)==1); }
int main() { int i,j; //update varible int exponent; //prompt exponent by user int *arr; //prompt coefficients by user arr = (int *)malloc(Max_Length ); //define the max array length if( arr == NULL ) //test whether the pointer of array points empty or not { return 0; } else { /* user input the exponent and coefficients which are stored in corresponding varible and array. print the whole program. */ for (j=0;j<5;j++) { printf("Please enter the maximum degree of the polynomial "); scanf("%d",&exponent); //prompt the exponent by user if (exponent>=0) { printf("Please enter the coefficients "); /* print the terms of expression */ for (i=0;i<=exponent;i++) { scanf("%d",&arr[i]); //prompt coefficients by use } polynomial(exponent,arr); //print the polynomial expression derivative(exponent,arr); //print the derivative expression printf("\n\n\n"); } else { printf("\n\n\n"); } } free( arr ); //release the storage } return 0; }
int main(void) { while(1){ //loop forever printf("Please enter the maximum degree of the polynomial: "); scanf("%d",°ree); //input maximum degree. if (degree < 0 ){ break; //the program will exit when input less then 0. } printf("Please enter the coefficients: "); for (i=0;i<=degree;i++){ scanf("%d",&coef[i]); //input all coefficients from coef[1] to coef[i]. } polynomial(); //output all polynomial. printf("\n"); reciprocal(); //output all reciprocal. printf("\n"); selfreciprocal(); //output if it is self-reciprocal or not. } }
int main(void) { int i, loop, poldegree, size; for(loop=1; loop!=0;) // loop=1 --> the program keeps on running asking for new values, loop=0 --> the program terminates { printf("Please enter the maximum degree of the polynomial: "); scanf("%d", &poldegree); if (poldegree<0) // if the polynomial degree (poldegree) entered is negative then loop=0 and the program terminates loop=0; else { size = poldegree +1 ; int * coefficients = new int[size]; // we define the size of our array which depends on the polynomial degree entered by the user printf("Please enter the coefficients: "); for(i=0; i<=poldegree; i++) scanf("%d", &coefficients[i]); // it reads tha values of the coefficients which are placed into an array polynomial(coefficients, poldegree); printf("\n"); reciprocal_calc(coefficients, poldegree); printf("\n"); if(poldegree!=0) loop=reciprocal_check(coefficients, poldegree); else if(poldegree==0) { printf("The polynomial is self-reciprocal \n\n"); loop=0; } if (loop==1) // if the polynomial is not self-reciprocal then the array's values should be deleted sp that the next coefficients can be entered { free(coefficients); printf("\n\n\n"); } } } return 0; }
int main(void) { while(1){ //loop forever printf("Please enter the maximum degree of the polynomial: "); scanf("%d",°ree); //input maximum degree. if (degree < 0 ){ break; //the program will exit when input less then 0. } printf("Please enter the coefficients: "); for (i=0;i<=degree;i++){ scanf("%d",&*(coef+i)); //input all coefficients from coef[1] to coef[i]. } polynomial(); //output all polynomial. if (coef !=NULL){ free(coef); } printf("\n"); } }