1 /*
2  * This file is part of MPSolve 3.2.1
3  *
4  * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa.
5  * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
6  *
7  * Authors:
8  *   Dario Andrea Bini <bini@dm.unipi.it>
9  *   Giuseppe Fiorentino <fiorent@dm.unipi.it>
10  *   Leonardo Robol <leonardo.robol@unipi.it>
11  */
12 
13 #include <mps/mps.h>
14 #include <math.h>
15 
16 #define MPS_STARTING_SIGMA (0.66 * (PI / ctx->n))
17 #define pi2 6.283184
18 
19 void
mps_general_fstart(mps_context * ctx,mps_polynomial * p,mps_approximation ** approximations)20 mps_general_fstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations)
21 {
22   int i;
23   double sigma, ang;
24 
25   if (ctx->random_seed)
26     sigma = drand ();
27   else
28     {
29       sigma = ctx->last_sigma = MPS_STARTING_SIGMA;
30     }
31 
32   /* In the case of user-defined polynomial choose as starting
33    * approximations equally spaced points in the unit circle.  */
34   ang = pi2 / ctx->n;
35   for (i = 0; i < ctx->n; i++)
36     {
37       cplx_set_d (approximations[i]->fvalue, cos (ang * i + sigma),
38                   sin (ang * i + sigma));
39     }
40 }
41 
42 void
mps_general_dstart(mps_context * ctx,mps_polynomial * p,mps_approximation ** approximations)43 mps_general_dstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations)
44 {
45   int i;
46   double sigma, ang;
47 
48   if (ctx->random_seed)
49     sigma = drand ();
50   else
51     {
52       sigma = ctx->last_sigma = MPS_STARTING_SIGMA;
53     }
54 
55   /* In the case of user-defined polynomial choose as starting
56    * approximations equally spaced points in the unit circle.  */
57   ang = pi2 / ctx->n;
58   for (i = 0; i < ctx->n; i++)
59     {
60       cdpe_set_d (approximations[i]->dvalue, cos (ang * i + sigma),
61                   sin (ang * i + sigma));
62     }
63 }
64 
65 void
mps_general_mstart(mps_context * ctx,mps_polynomial * p,mps_approximation ** approximations)66 mps_general_mstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations)
67 {
68   int i;
69   double sigma, ang;
70 
71   if (ctx->random_seed)
72     sigma = drand ();
73   else
74     {
75       sigma = ctx->last_sigma = MPS_STARTING_SIGMA;
76     }
77 
78   /* In the case of user-defined polynomial choose as starting
79    * approximations equally spaced points in the unit circle.  */
80   ang = pi2 / ctx->n;
81   for (i = 0; i < ctx->n; i++)
82     {
83       cplx_t tmp;
84       cplx_set_d (tmp, cos (ang * i + sigma),
85                   sin (ang * i + sigma));
86       mpc_set_cplx (approximations[i]->mvalue, tmp);
87     }
88 }
89