Changeset bedce5a in tol


Ignore:
Timestamp:
Feb 8, 2012, 7:03:06 PM (15 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
e23352b
Parents:
e6d6935
Message:

Fixes #1359

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@4085 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tol
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tol/bmath/mathobjects/tol_bpolyn.h

    re6d6935 rbedce5a  
    2424
    2525#include <tol/tol_bmonome.h>
     26#include <boost/math/common_factor_rt.hpp>
    2627#include <limits>
    2728
    … …  
    7879  BText Info() const { return(Name()); }
    7980  BInt Degree() const { return((!this->size_)?std::numeric_limits<int>::min():(*this)(this->size_-1).Degree()); }
     81  BInt Period() const;
    8082  BBool IsNull() const { return((Degree()==0) && (Coef(0)==Any(0.0)));}
    8183  Any Eval (const Any& x) const;
    … …  
    9597  void Aggregate();
    9698  void ChangeBF(const BPolyn<Any>& pol);
     99  void InverseRoots(const BPolyn<Any>& pol);
    97100  BPolyn<Any> NextSchur() const;
    98   Any    Schur(BBool complete = BTRUE) const;
    99   Any    StationaryValue(BBool complete = BTRUE) const;
     101  Any    Schur(BBool complete) const;
     102  Any    StationaryValue(BBool complete) const;
    100103  BBool IsStationary() const;
    101104
    … …  
    325328}
    326329
     330//--------------------------------------------------------------------
     331template <class Any>
     332void BPolyn<Any>::InverseRoots(const BPolyn<Any>& pol)
     333//--------------------------------------------------------------------
     334{
     335  int s = pol.Size();
     336  int n = pol.Degree();
     337  int i, j, deg;
     338  Any coef;
     339  ReallocBuffer(s);
     340  for(i=0; i<s; i++)
     341  {
     342    j = s-1-i;
     343    deg  = pol(i).Degree();
     344    coef = pol(i).Coef();
     345    (*this)(j).PutDegree(n-deg);
     346    (*this)(j).PutCoef(coef);
     347  }
     348}
    327349
    328350//--------------------------------------------------------------------
    … …  
    331353//--------------------------------------------------------------------
    332354{
     355//Std(BText("\nTRACE  NextSchur 1 this=")+Name());
    333356  BInt n = Degree();
    334   Any first = (*this).Coef(0);
    335   Any last  = (*this).Coef(n);
    336 //Std(BText("\nNextSchur this=")+Name());
    337 //Std(BText("\n       First : ")+first.Name()   + ";  Last : "+last.Name());
     357  BArray<Any> a(n+1);
     358  int k;
     359  for(k=0; k<=n; k++) { a[k] = Coef(k); }
     360  Any a0  = a[0];
     361  Any an  = a[n];
     362  Any c;
     363//Std(BText("\na[0]: ")+a0.Name()+"; a[n]:"+an.Name());
    338364  BPolyn<Any> next;
    339365  next.ReallocBuffer(n);
    340   for(BInt i=1; i<=n; i++)
    341   {
    342     next(i-1).PutDegree(i-1);
    343     next(i-1).PutCoef(last*Coef(i) - first*Coef(n-i));
    344   //Std(BText("\n       Coef(i)     : ")+Coef(i).Name() + ";  Coef(n-i)    : "+Coef(n-i).Name() + ";  next(i-1)    : "+next.Coef(i-1).Name());
    345   }
     366  for(k=0; k<n; k++)
     367  {
     368    c = an*a[k+1] - a0*a[n-k-1];
     369    next(k).PutCoef(c);
     370    next(k).PutDegree(k);
     371  //Std(BText("\na[k+1]: ")+a[k+1].Name()+"; a[n-k-1]:"+a[n-k-1].Name()+"; next(i-1):"+c.Name());
     372  }
     373//Std(BText("\nTRACE NextSchur 2 next=")+next.Name());
    346374  next.Aggregate();
    347 //Std(BText("\nNextSchur next=")+next.Name());
     375//Std(BText("\nNextSchur 3 next=")+next.Name());
     376//if(next.Degree()>0) { next /= next.Coef(next.Degree()); }
     377//Std(BText("\nTRACE NextSchur 4 next=")+next.Name());
    348378  return(next);
    349379}
    … …  
    354384Any BPolyn<Any>::Schur(BBool complete) const
    355385
    356 /*! Returns true if all roots in this polyn are in the unit circle
    357  */
    358 //--------------------------------------------------------------------
    359 {
    360 //  Std(BText("\n  Schur      : ")+Name());
    361     if(Degree()==0) { return(-1); }
    362     else
    363     {
    364     Any a = Abs((*this)(       0).Coef());
    365     Any b = Abs((*this)(this->Size()-1).Coef());
    366     if((!complete && (b<=a)) || (Degree()==1)) {
    367         return(Abs(b/a));   
    368     } else {
    369         return(NextSchur().Schur(complete));
    370     }
    371     }
    372 
    373 }
    374 
     386/*! Returns a value great than 1 if there are no roots out of
     387 *  the unit circle
     388 */
     389//--------------------------------------------------------------------
     390{
     391//Std(BText("\nTRACE  Schur : ")+Name());
     392  int s = this->Size();
     393  int n = this->Degree();
     394  if(s==1) { return(2); }
     395  Any a0 = Abs(this->Coef(0));
     396  Any an = Abs(this->Coef(n));
     397  Any v = 1.0+(an-a0)/(an+a0);
     398  if((!complete && (v<=1)) || (s==2))
     399  {
     400    return(v);
     401  }
     402  else
     403  {
     404    return(NextSchur().Schur(complete));
     405  }
     406}
     407
     408//--------------------------------------------------------------------
     409template <class Any>
     410BInt BPolyn<Any>::Period() const
     411//--------------------------------------------------------------------
     412{
     413  int s = this->Size();
     414  int i;
     415  int deg;
     416  int gcd = (*this)(0).Degree();
     417  for(i=1; i<s; i++)
     418  {
     419    deg = (*this)(i).Degree();
     420    if(deg) { gcd = boost::math::gcd(gcd,deg); }
     421  }
     422  return(gcd);
     423}
    375424
    376425//--------------------------------------------------------------------
    … …  
    378427Any BPolyn<Any>::StationaryValue(BBool complete) const
    379428
    380 /*! Returns a value great than 1 if all roots in this polyn are
    381  *  circle
    382  */
    383 //--------------------------------------------------------------------
    384 {
    385     BInt n = this->Degree();
    386     BPolyn sym;
    387     sym.ReallocBuffer(n+1);
    388     for(BInt i=0; i<=n; i++)
    389     {
    390       sym(i).PutDegree(i);
    391       Any v = this->Coef(n-i);
    392       if(v>-3.925e-323 && v<=0) { v=-3.925e-323; }
    393       if(v<+3.925e-323 && v>=0) { v=+3.925e-323; }
    394       sym(i).PutCoef(v);
    395     }
    396 //Std(BText("\nStationary : ")+Name());
    397     return(sym.Schur(complete));
     429/*! Returns a value great than 1 if there are no roots inside
     430 *  the unit circle
     431 */
     432//--------------------------------------------------------------------
     433{
     434//Std(BText("\nTRACE  StationaryValue : ")+Name());
     435  int s = this->Size();
     436  int n = this->Degree();
     437  if(s==1)
     438  {
     439    if(n==0) { return(2); }
     440    else     { return(0); }
     441  }
     442  int i, j;
     443  int deg;
     444  Any coef;
     445  BPolyn sym;
     446  int gcd = Period();
     447//Std(BText("\nTRACE  StationaryValue  gcd=")+gcd);
     448  int m = n/gcd;
     449  sym.ReallocBuffer(s);
     450  for(i=0; i<s; i++)
     451  {
     452    j = s-1-i;
     453    deg  = (*this)(i).Degree();
     454    coef = (*this)(i).Coef();
     455    sym(j).PutDegree(m-deg/gcd);
     456    sym(j).PutCoef(coef);
     457  }
     458  return(sym.Schur(complete));
    398459}
    399460
  • tol/btol/polynomial_type/polgra.cpp

    re6d6935 rbedce5a  
    319319//--------------------------------------------------------------------
    320320{
    321     contens_.ChangeBF(Pol(Arg(1)));
     321  contens_.ChangeBF(Pol(Arg(1)));
     322}
     323
     324//--------------------------------------------------------------------
     325DeclareContensClass(BPol, BPolTemporary, BPolInverseRoots);
     326DefIntOpr(1, BPolInverseRoots, "InverseRoots", 1, 1,
     327  "(Polyn p)",
     328  I2("Returns a polynomial q which have inverse roots of given one by "
     329     "mean of this formulae:",
     330     "Devuelve un polinomio q cuyas raíces son las inversas de las del "
     331     "polinomio dado por medio de esta fórmula:")+"\n"+
     332     " p(x) = Sum(a[k]*x^k,     k=0...n) "
     333     " q(x) = Sum(a[k]*x^(n-k), k=0...n) ",
     334          BOperClassify::RetardPolynomial_);
     335//--------------------------------------------------------------------
     336void BPolInverseRoots::CalcContens()
     337//--------------------------------------------------------------------
     338{
     339  contens_.InverseRoots(Pol(Arg(1)));
    322340}
    323341
  • tol/btol/real_type/datgrav.cpp

    re6d6935 rbedce5a  
    13231323
    13241324//--------------------------------------------------------------------
     1325  DeclareContensClass(BDat, BDatTemporary, BDatPolPeriod);
     1326  DefExtOpr(1, BDatPolPeriod, "PolPeriod", 1, 1, "Polyn",
     1327  "(Polyn pol)",
     1328  I2("Returns the period of a polynomial, i.e. the greatest common "
     1329     "divisor of the degrees of all its monomials.",
     1330     "Devuelve el periodo de un polinomio, entendido como el máximo "
     1331     "común divisor de los grados de todos sus monomios."),
     1332     BOperClassify::RetardPolynomial_);
     1333  void BDatPolPeriod::CalcContens()
     1334//--------------------------------------------------------------------
     1335{
     1336  contens_ = Pol(Arg(1)).Period();
     1337}
     1338
     1339//--------------------------------------------------------------------
    13251340  DeclareContensClass(BDat, BDatTemporary, BDatStationaryValue);
    13261341  DefExtOpr(1, BDatStationaryValue, "StationaryValue", 1, 1, "Polyn",
    … …  
    13341349//--------------------------------------------------------------------
    13351350{
    1336   contens_ = Pol(Arg(1)).StationaryValue(BTRUE);
     1351  contens_ = Pol(Arg(1)).StationaryValue(BFALSE);
    13371352}
    13381353
Note: See TracChangeset for help on using the changeset viewer.