/* nag_quartic_roots (c02alc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * NAG C Library * * Mark 6, 2000. * Mark 7, revised, 2001. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; double a, b, c, d, e; double *errest = 0, *zeroi = 0, *zeror = 0; Integer i; Integer exit_status = 0; NagError fail; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_quartic_roots (c02alc) Example Program Results\n\n"); if ( !(errest = NAG_ALLOC(4, double)) || !(zeroi = NAG_ALLOC(4, double)) || !(zeror = NAG_ALLOC(4, double)) ) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%lf %lf %lf %lf %lf", &e, &a, &b, &c, &d); /* nag_quartic_roots (c02alc). * Zeros of a real quartic polynomial with real coefficients */ nag_quartic_roots(e, a, b, c, d, zeror, zeroi, errest, &fail); if (fail.code == NE_NOERROR) { fprintf(fpout, " Roots of quartic equation Error estimates\n"); fprintf(fpout, " (machine-dependent)\n\n"); for (i = 0; i <= 3; ++i) { fprintf(fpout, "%s %10.5f %10.5f%s %g\n", " z =", zeror[i], zeroi[i], "*i", errest[i]); } } else { fprintf(fpout, "Error from nag_quartic_roots (c02alc).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (errest) NAG_FREE(errest); if (zeroi) NAG_FREE(zeroi); if (zeror) NAG_FREE(zeror); return exit_status; }