1 #include <stdio.h>
2 #include "quadratic-poly.h"
3
4 char * starting_file = NULL;
5
main(int argc,char * argv[])6 int main (int argc, char * argv[]) {
7
8 /* Create a new mps_context that will be used to solve a Quadratic polynomial
9 * of the selected degree. */
10 mps_context * ctx = mps_context_new ();
11
12 if (argc > 3 || argc < 2)
13 {
14 fprintf (stderr,
15 "Usage: %s n [starting_file] \n"
16 "\n"
17 "Parameters: \n"
18 " - n is the level of the Quadratic polynomial to solve\n\n"
19 " - starting_file is an optional file with the approximations that shall be \n"
20 " use as starting points.\n",
21 argv[0]);
22 return EXIT_FAILURE;
23 }
24
25 int n = atoi (argv[1]);
26
27 if (n <= 0)
28 {
29 fprintf (stderr, "Please specify a positive integer as Quadratic level.\n");
30 return EXIT_FAILURE;
31 }
32
33 if (argc == 3)
34 starting_file = argv[2];
35
36 mps_quadratic_poly *mp = mps_quadratic_poly_new (ctx, n);
37
38 mps_context_set_input_poly (ctx, MPS_POLYNOMIAL (mp));
39 mps_context_select_algorithm (ctx, MPS_ALGORITHM_SECULAR_GA);
40 mps_context_set_starting_phase (ctx, float_phase);
41 mps_context_set_avoid_multiprecision (ctx, true);
42 mps_mpsolve (ctx);
43
44 mps_approximation ** apprs = mps_context_get_approximations (ctx);
45 for (int i = 0; i < mps_context_get_degree (ctx); i++)
46 {
47 cplx_t value;
48 mps_approximation_get_fvalue (ctx, apprs[i], value);
49 printf (" "); cplx_out_str (stdout, value); printf ("\n");
50
51 mps_approximation_free (ctx, apprs[i]);
52 }
53 free (apprs);
54
55 mps_quadratic_poly_free (ctx, MPS_POLYNOMIAL (mp));
56 mps_context_free (ctx);
57
58 return EXIT_SUCCESS;
59 }
60
61