rootQ.cpp
Go to the documentation of this file.
1 /* $Id: rootQ.cpp 513 2011-03-03 01:43:48Z pbelotti $
2  *
3  * Name: rootQ.cpp
4  * Author: Pietro Belotti
5  * Purpose: find roots of polynomial Q^k(x) (see Liberti and Pantelides, 2003)
6  *
7  * (C) Carnegie-Mellon University, 2006-11.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #include <math.h>
12 #include <stdio.h>
13 
14 #include "CouenneTypes.hpp"
15 #include "CouennePrecisions.hpp"
16 
17 namespace Couenne {
18 
19 /* compute Q(x) */
20 
21 CouNumber Q (register int k, CouNumber x) {
22 
23  register CouNumber xp = x, Q = 1.;
24 
25  k *= 2;
26 
27  for (register int i=2; i<=k; i++) {
28 
29  Q += (CouNumber) i * xp;
30  xp *= x;
31  }
32 
33  return Q;
34 }
35 
36 
37 /*
38  * Find roots of polynomial $Q^k(x) = \sum_{i=1}^{2k} i x^{i-1}$. Used
39  * in convexification of powers with odd exponent
40  */
41 
42 CouNumber rootQ (int k) {
43 
44  if (k==1) return - 0.5; // for x^3, solution is -1/2
45  else {
46 
47  register CouNumber
48  l = - 1.0 + 0.5 / k,
49  u = - 0.5,
50  /* Ql = Q (k, l), Qu = Q (k, u), */
51  Qm,
52  midpoint;
53  do {
54 
55  midpoint = 0.5 * (l+u); /* (- Ql * u + Qu * l) / (Qu - Ql); */
56  Qm = Q (k, midpoint);
57 
58  /* printf ("[%.4f, %.4f] --> %.4f: %.24f\n", l, u, midpoint, Qm); */
59 
60  if (Qm<0) {l = midpoint; /* Ql = Qm; */ Qm = - Qm;} // invert sign to avoid fabs() in termination check
61  else {u = midpoint; /* Qu = Qm; */}
62 
63  } while (Qm > 1e-15);
64 
65  return midpoint;
66  }
67 }
68 
69 }
70 
71 #ifdef DEBUG_ROOTQ
72 int main () {
73 
74  register int k;
75  CouNumber x, q;
76 
77  for (k=6; --k;) {
78 
79  printf ("root, %3d -> %.15f\n", 2*k+1, rootQ (k));
80  /*
81  printf ("k=%3d: ", 2*k+1);
82  for (x = -1.0; x < 0.4; x += 0.1) {
83  // Q (k, x, &q, NULL, NULL);
84  printf ("[%.2f, %.3f] ", x, rootQ);
85  }
86  printf ("\n");
87  */
88  }
89 }
90 
91 #endif
CouNumber rootQ(int k)
Find roots of polynomial $Q^k(x) = .
Definition: rootQ.cpp:42
int main(int argc, char *argv[])
Definition: BB_tm.cpp:32
CouNumber Q(register int k, CouNumber x)
Definition: rootQ.cpp:21
void fint fint fint real fint real real real real real real real real real * e
void fint fint * k
double CouNumber
main number type in Couenne
void fint fint fint real fint real * x