val_dern_1d.C

00001 /*
00002  *   Copyright (c) 2004 Jerome Novak
00003  *
00004  *   This file is part of LORENE.
00005  *
00006  *   LORENE is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   LORENE is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with LORENE; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 char val_dern_1d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/val_dern_1d.C,v 1.1 2004/02/17 09:21:39 j_novak Exp $" ;
00024 
00025 /*
00026  * $Id: val_dern_1d.C,v 1.1 2004/02/17 09:21:39 j_novak Exp $
00027  * $Log: val_dern_1d.C,v $
00028  * Revision 1.1  2004/02/17 09:21:39  j_novak
00029  * New functions for calculating values of the derivatives of a function
00030  * using its Chebyshev coefficients.
00031  *
00032  *
00033  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/val_dern_1d.C,v 1.1 2004/02/17 09:21:39 j_novak Exp $
00034  *
00035  */
00036 
00037 #include "type_parite.h"
00038 #include "tbl.h"
00039 
00040 /*
00041  * Functions computing value of f^(n) at boundaries of the interval [-1, 1],
00042  * using the Chebyshev expansion of f. Note: n=0 works too.
00043  * 
00044  * Input : 1-dimensional Tbl containing the Chebyshev coefficients of f.
00045  *      int base : base of spectral expansion.
00046  *
00047  * Output : double : the value of the n-th derivative of f at x=+/- 1.
00048  * 
00049  */
00050 
00051 
00052 double val1_dern_1d(int n, const Tbl& tb, int base_r)
00053 {
00054 
00055   //This function should be OK for any radial base
00056   assert ( (base_r == R_CHEB) || (base_r == R_CHEBI) || (base_r == R_CHEBP) ||
00057        (base_r == R_CHEBU) ) ; 
00058 
00059   assert (n>=0) ;
00060   assert (tb.get_ndim() == 1) ;
00061   int nr = tb.get_dim(0) ;
00062 
00063   double resu = 0. ;
00064 
00065   int n_ini = ( (base_r == R_CHEBP) || (base_r == R_CHEBI) ) ? n / 2 : n ;
00066 
00067   double *tbi = &tb.t[n_ini] ;
00068   for (int i=n_ini; i<nr; i++) {
00069     double fact = 1. ;
00070     int ii = i ;
00071     if (base_r == R_CHEBP) ii *= 2 ;
00072     if (base_r == R_CHEBI) ii = 2*i + 1 ;
00073     for (int j=0; j<n; j++) 
00074       fact *= double(ii*ii - j*j)/double(2*j + 1) ;
00075     resu += fact * (*tbi) ;
00076     tbi++ ;
00077   }
00078 
00079   return resu ;
00080 }
00081 
00082 double valm1_dern_1d(int n, const Tbl& tb, int base_r)
00083 {
00084 
00085   //This function should be OK for any radial base
00086   assert ( (base_r == R_CHEB) || (base_r == R_CHEBI) || (base_r == R_CHEBP) ||
00087        (base_r == R_CHEBU) ) ; 
00088 
00089   assert (n>=0) ;
00090   assert (tb.get_ndim() == 1) ;
00091   int nr = tb.get_dim(0) ;
00092 
00093   double resu = 0. ;
00094   double parite, fac ;
00095   int n_ini ;
00096   switch (base_r) {
00097   case R_CHEBP:
00098     n_ini = n / 2 ;
00099     parite = 1 ;
00100     fac = (n%2 == 0 ? 1 : -1) ;
00101     break ;
00102   case R_CHEBI: 
00103     n_ini = n / 2 ;
00104     fac = (n%2 == 0 ? -1 : 1) ;
00105     parite = 1 ;
00106     break ;
00107   default:
00108     n_ini = n ;
00109     parite = -1 ;
00110     fac = 1 ;
00111     break ;
00112   }
00113   double *tbi = &tb.t[n_ini] ;
00114   
00115   for (int i=n_ini; i<nr; i++) {
00116     double fact = fac ;
00117     int ii = i ;
00118     if (base_r == R_CHEBP) ii *= 2 ;
00119     if (base_r == R_CHEBI) ii = 2*i + 1 ;
00120     for (int j=0; j<n; j++)
00121       fact *= double(ii*ii - j*j)/double(2*j + 1) ;
00122     resu += fact * (*tbi) ;
00123     fac *= parite ;
00124     tbi++ ;
00125   }
00126 
00127   return resu ;
00128 }

Generated on Tue Feb 7 01:35:21 2012 for LORENE by  doxygen 1.4.6