Blame integration/chebyshev2.c

Packit 67cb25
/* integration/chebyshev2.c
Packit 67cb25
 * 
Packit 67cb25
 * Copyright (C) 2017 Konrad Griessinger, Patrick Alken
Packit 67cb25
 * 
Packit 67cb25
 * This program is free software; you can redistribute it and/or modify
Packit 67cb25
 * it under the terms of the GNU General Public License as published by
Packit 67cb25
 * the Free Software Foundation; either version 3 of the License, or (at
Packit 67cb25
 * your option) any later version.
Packit 67cb25
 * 
Packit 67cb25
 * This program is distributed in the hope that it will be useful, but
Packit 67cb25
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 67cb25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 67cb25
 * General Public License for more details.
Packit 67cb25
 * 
Packit 67cb25
 * You should have received a copy of the GNU General Public License
Packit 67cb25
 * along with this program; if not, write to the Free Software
Packit 67cb25
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit 67cb25
 */
Packit 67cb25
Packit 67cb25
/*
Packit 67cb25
 * The code in this module is based on IQPACK, specifically the LGPL
Packit 67cb25
 * implementation found in HERMITE_RULE:
Packit 67cb25
 * https://people.sc.fsu.edu/~jburkardt/c_src/hermite_rule/hermite_rule.html
Packit 67cb25
 */
Packit 67cb25
Packit 67cb25
#include <stdio.h>
Packit 67cb25
#include <gsl/gsl_errno.h>
Packit 67cb25
#include <gsl/gsl_math.h>
Packit 67cb25
#include <gsl/gsl_integration.h>
Packit 67cb25
#include <gsl/gsl_sf_gamma.h>
Packit 67cb25
Packit 67cb25
static int
Packit 67cb25
chebyshev2_check(const size_t n, const gsl_integration_fixed_params * params)
Packit 67cb25
{
Packit 67cb25
  (void) n;
Packit 67cb25
Packit 67cb25
  if (fabs(params->b - params->a) <= GSL_DBL_EPSILON)
Packit 67cb25
    {
Packit 67cb25
      GSL_ERROR("|b - a| too small", GSL_EDOM);
Packit 67cb25
    }
Packit 67cb25
  else if (params->a >= params->b)
Packit 67cb25
    {
Packit 67cb25
      GSL_ERROR("lower integration limit must be smaller than upper limit", GSL_EDOM);
Packit 67cb25
    }
Packit 67cb25
  else
Packit 67cb25
    {
Packit 67cb25
      return GSL_SUCCESS;
Packit 67cb25
    }
Packit 67cb25
}
Packit 67cb25
Packit 67cb25
static int
Packit 67cb25
chebyshev2_init(const size_t n, double * diag, double * subdiag, gsl_integration_fixed_params * params)
Packit 67cb25
{
Packit 67cb25
  size_t i;
Packit 67cb25
Packit 67cb25
  /* construct the diagonal and subdiagonal elements of Jacobi matrix */
Packit 67cb25
  for (i = 0; i < n; i++)
Packit 67cb25
    {
Packit 67cb25
      diag[i] = 0.0;
Packit 67cb25
      subdiag[i] = 0.5;
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  params->zemu = M_PI_2;
Packit 67cb25
  params->shft = 0.5*(params->b + params->a);
Packit 67cb25
  params->slp = 0.5*(params->b - params->a);
Packit 67cb25
  params->al = 0.5;
Packit 67cb25
  params->be = 0.5;
Packit 67cb25
Packit 67cb25
  return GSL_SUCCESS;
Packit 67cb25
}
Packit 67cb25
Packit 67cb25
static const gsl_integration_fixed_type chebyshev2_type =
Packit 67cb25
{
Packit 67cb25
  chebyshev2_check,
Packit 67cb25
  chebyshev2_init
Packit 67cb25
};
Packit 67cb25
Packit 67cb25
const gsl_integration_fixed_type *gsl_integration_fixed_chebyshev2 = &chebyshev2_type;