Changeset 8279431 in tol


Ignore:
Timestamp:
May 8, 2012, 5:13:14 PM (14 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
cc73774
Parents:
055659c
Message:

New built-in function gsl_poly_complex_solve: Returns complex roots of given polynomial in a real matrix with two columns

Refs #1136

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/matrix_type/matgra.cpp

    r055659c r8279431  
    5656#include <gsl/gsl_statistics.h>
    5757#include <gsl/gsl_math.h>
     58#include <gsl/gsl_poly.h>
    5859#include <tol/tol_fftw.h>
    5960
    … …  
    72957296
    72967297
    7297 /* */
     7298struct complex
     7299{
     7300  double x;
     7301  double y;
     7302};
     7303
     7304//--------------------------------------------------------------------
     7305BInt ComplexRootCmp(const void* v1, const void* v2)
     7306
     7307/*! Compairs two BParam receiving the pointers.
     7308 */
     7309//--------------------------------------------------------------------
     7310{
     7311  complex& z1 = *((complex*)v1);
     7312  complex& z2 = *((complex*)v2);
     7313  double z1m = z1.x*z1.x+z1.y*z1.y;
     7314  double z2m = z2.x*z2.x+z2.y*z2.y;
     7315  if(z1m < z2m) { return(-1); }
     7316  if(z1m > z2m) { return( 1); }
     7317  if(z1.x<z2.x) { return(-1); }
     7318  if(z1.x>z2.x) { return( 1); }
     7319  if(z1.y<z2.y) { return(-1); }
     7320  if(z1.y>z2.y) { return( 1); }
     7321  return(0);
     7322}
     7323
     7324//--------------------------------------------------------------------
     7325DeclareContensClass(BMat, BMatTemporary, BMat_gsl_poly_complex_solve);
     7326DefExtOpr(1, BMat_gsl_poly_complex_solve, "gsl_poly_complex_solve", 1, 1,
     7327  "Polyn",
     7328  "(Polyn a)",
     7329  I2(
     7330  "Returns complex roots of given polynomial in a real matrix with "
     7331  "two columns",
     7332  "Devuelve las raíces complejas de un polinomio en una matriz real "
     7333  "de dos columnas"),
     7334  BOperClassify::MatrixAlgebra_);
     7335//--------------------------------------------------------------------
     7336void BMat_gsl_poly_complex_solve::CalcContens()
     7337//--------------------------------------------------------------------
     7338{
     7339  BPol& pol = Pol(Arg(1));
     7340  int n = pol.Degree();
     7341  int s = pol.Size();
     7342  BArray<double> a(n+1);
     7343  contens_.Alloc(n,2);
     7344  double* z = (double*)contens_.GetData().GetBuffer();
     7345  int k, d;
     7346  for(k=0; k<s; k++)
     7347  {
     7348    d = pol[k].Degree();
     7349    a[d] = pol[k].Coef().Value();
     7350  }
     7351  gsl_poly_complex_workspace * w = gsl_poly_complex_workspace_alloc (n+1);
     7352  gsl_poly_complex_solve (a.Buffer(), n+1, w, z);
     7353  BArray<complex> row;
     7354  row.AllocBuffer(n);
     7355  memcpy(row.GetBuffer(),z,sizeof(double)*n*2);
     7356  row.Sort(ComplexRootCmp);
     7357  memcpy(z,row.Buffer(),sizeof(double)*n*2);
     7358  gsl_poly_complex_workspace_free(w);
     7359}
     7360/* */
Note: See TracChangeset for help on using the changeset viewer.