int main(void){ int degree; printf("Please enter the maximum degree of the polynomial: "); scanf("%d", °ree); /* The degree is input by the user for use by the functions */ while(degree>=0){ /* while loop allows program to keep running until negative degree is entered*/ printf("Please enter the coefficients: "); scan_coefficients(degree); /* The coefficients are scanned and returned through memory allocation calloc as the array "coefficient_array" for use in the main functions*/ printf("The polynomial is"); print_polynomial(degree, coefficient_array); /* The polynomial is printed normally */ printf("\nIts derivative is"); print_derivative(degree, coefficient_array); /* The polynomial is printed as its derivative */ printf("\n\nPlease enter the maximum degree of the polynomial: "); /*Input is repeated to allow program loop*/ scanf("%d", °ree); } /* Terminate the main function if degree is negative*/ }
void evaluate(double * polynomial, int degree, double * inputlist, int num_inputs, double (evaluate_function)(double *, int, double)) { int i; printf("p(x) = "); print_polynomial(polynomial, degree); printf("\n"); for (i = 0; i < num_inputs; i++) { double input = inputlist[i]; double output = evaluate_function(polynomial, degree, input); printf("p(%.1lf) = %lf\n", input, output); } }
main(){ int degree,i,*ptr,p,t,k,l,j; Polynomial *g = malloc(sizeof(Polynomial)); Polynomial *h = malloc(sizeof(Polynomial)); Polynomial *r = malloc(sizeof(Polynomial)); Polynomial *q = malloc(sizeof(Polynomial)); printf("Polynomial Division\n"); printf("Enter p of Zp[X] : "); scanf("%d",&p); printf("Enter polynomial g belonging to Z%d[X] :\n",p); printf("Enter k (degree+1): "); scanf("%d",&k); //k-1 is the degree init_polynomial(g,k-1); printf("Enter its coffecients\n"); for(i=0;i<= g->deg;i++){ scanf("%d",&g->cof[i]); } printf("Enter polynomial h belonging to Z%d[X] :\n",p); printf("Enter l (degree+1): "); scanf("%d",&l); //l-1 is the degree init_polynomial(h,l-1); printf("Enter its coffecients\n"); for(i=0;i<= h->deg;i++){ scanf("%d",&h->cof[i]); } //print_polynomial(g); //print_polynomial(h); if(polynomial_division(g, h, q, r, p) != SUCCESS){ printf("Not able to do polynomial division\n"); exit(1); } printf("q is:\n"); print_polynomial(q); printf("r is:\n"); print_polynomial(r); }
void print_polynomial_system(FILE *OUT, polynomial_system *F) /***************************************************************\ * USAGE: user-friendly printing of polynomial system F to a file* \***************************************************************/ { int i, numVars = F->numVariables, numPolys = F->numPolynomials, numExps = F->numExponentials; int numFuncs = numPolys + numExps; // print variables fprintf(OUT, "\nvariable "); for (i = 0; i < numVars; i++) { fprintf(OUT, "%c%d", i < numPolys ? 'x' : 'y', i < numPolys ? i + 1 : i + 1 - numPolys); if (i+1 < numVars) fprintf(OUT, ","); else fprintf(OUT, ";\n"); } // print functions fprintf(OUT, "function "); for (i = 0; i < numFuncs; i++) { fprintf(OUT, "F%d", i + 1); if (i + 1 < numVars) fprintf(OUT, ","); else fprintf(OUT, ";\n\n"); } // print the polynomials for (i = 0; i < numPolys; i++) { fprintf(OUT, "F%d = ", i + 1); print_polynomial(OUT, &F->polynomials[i], F->numPolynomials); fprintf(OUT, ";\n"); } // print the exponentials for (i = 0; i < numExps; i++) { fprintf(OUT, "F%d = ", numPolys + i + 1); print_exponential(OUT, &F->exponentials[i], F->numPolynomials); fprintf(OUT, ";\n"); } fprintf(OUT, "\n"); return; }
void main(void) { int gd = DETECT, gm; double points[6][2] = {-3, 2, -2, -1.5, -1, 0, 0, 0, 1, 1, 2, -1.5}; node *poly; if ((poly = lagrange(points, 6)) != NULL) print_polynomial(poly, "poly = "); else printf("Impossible !!!!"); getch(); initgraph(&gd, &gm, "c:\\tcpp\\bgi"); draw_points(points, 6, 0, 0, 100); draw(poly, 0, 0, -5, 5, 100, 0.05); getch(); closegraph(); }
void main( ) { init_polynomial( ); while(1){ input_degree( ); if(get_degree( ) <= -1) break; input_coef( ); print_polynomial( ); print_derivative( ); clear_polynomial( ); } }
/* * Print the content of a poly_buffer b */ static void print_poly_buffer_details(poly_buffer_t *b) { int32_t i, n; printf("poly buffer %p\n", b); printf(" i_size = %"PRIu32"\n", b->i_size); printf(" m_size = %"PRIu32"\n", b->m_size); printf(" nterms = %"PRIu32"\n", b->nterms); printf(" poly: "); print_polynomial(b->mono, b->nterms); printf("\n"); n = b->i_size; for (i=0; i<n; i++) { if (b->index[i] >= 0) { printf(" index[x!%"PRId32"] = %"PRId32"\n", i, b->index[i]); } } printf("\n"); }
/* * Print the content of a poly_buffer b */ static void print_poly_buffer(poly_buffer_t *b) { print_polynomial(b->mono, b->nterms); }