/home/coin/SVN-release/OS-2.2.0/Couenne/src/util/rootQ.cpp

Go to the documentation of this file.
00001 /* $Id: rootQ.cpp 154 2009-06-16 18:52:53Z pbelotti $ */
00002 /*
00003  * Name:    rootQ.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: find roots of polynomial Q^k(x) (see Liberti and Pantelides, 2003)
00006  *
00007  * (C) Carnegie-Mellon University, 2006. 
00008  * This file is licensed under the Common Public License (CPL)
00009  */
00010 
00011 #include <math.h>
00012 #include <stdio.h>
00013 
00014 #include "CouenneTypes.hpp"
00015 #include "CouennePrecisions.hpp"
00016 
00017 
00018 /* compute Q(x)*/
00019 
00020 CouNumber Q (register int k, CouNumber x) {
00021 
00022   register CouNumber xp, Q;
00023 
00024   k *= 2;
00025 
00026   xp = x;
00027   Q = 1;
00028 
00029   for (register int i=2; i<=k; i++) {
00030 
00031     Q += (CouNumber) i * xp;
00032     xp *= x;
00033   }
00034 
00035   return Q;
00036 }
00037 
00038 
00039 /*
00040  * Find roots of polynomial $Q^k(x) = \sum_{i=1}^{2k} i x^{i-1}$. Used
00041  *  in convexification of powers with odd exponent
00042  */
00043 
00044 CouNumber rootQ (int k) {
00045 
00046   if (k==1) return - 0.5;
00047   else {
00048 
00049     register CouNumber l  = - 1.0 + 0.5 / k, 
00050                        u  = - 0.5,
00051                        Ql = Q (k, l), Qu = Q (k, u), Qm,
00052                        midpoint;
00053     do {
00054 
00055       midpoint = 0.5 * (l+u); /* (- Ql * u + Qu * l) / (Qu - Ql); */
00056       Qm = Q (k, midpoint);
00057 
00058       /*      printf ("[%.4f, %.4f] --> %.4f: %.24f\n", l, u, midpoint, Qm); */
00059 
00060       if (Qm<0) {l = midpoint; Ql = Qm; Qm = - Qm;}
00061       else      {u = midpoint; Qu = Qm;}
00062 
00063     } while (Qm > 1e-15);
00064 
00065     return midpoint;
00066   }
00067 }
00068 
00069 #ifdef DEBUG_ROOTQ
00070 int main () {
00071 
00072   register int k;
00073   CouNumber x, q;
00074 
00075   for (k=6; --k;) {
00076 
00077     printf ("root, %3d -> %.15f\n", 2*k+1, rootQ (k));
00078     /*
00079     printf ("k=%3d: ", 2*k+1);
00080     for (x = -1.0; x < 0.4; x += 0.1) {
00081       //      Q (k, x, &q, NULL, NULL); 
00082       printf ("[%.2f, %.3f] ", x, rootQ);
00083     }
00084     printf ("\n");
00085     */
00086   }
00087 }
00088 #endif

Generated on Thu Aug 5 03:02:57 2010 by  doxygen 1.4.7