102 #define INTREPID_POLYLIB_STOP 50
105 #define INTREPID_POLYLIB_POLYNOMIAL_DEFLATION 0
107 #ifdef INTREPID_POLYLIB_POLYNOMIAL_DEFLATION
108 #define jacobz(n,z,alpha,beta) Jacobz(n,z,alpha,beta)
111 #define jacobz(n,z,alpha,beta) JacZeros(n,z,alpha,beta)
116 template <
class Scalar>
119 Scalar fac, one = 1.0, two = 2.0, apb = alpha + beta;
127 for(i = 0; i < np; ++i) w[i] = fac/(w[i]*w[i]*(one-z[i]*z[i]));
133 template <
class Scalar>
142 Scalar fac, one = 1.0, two = 2.0, apb = alpha + beta;
151 for(i = 0; i < np; ++i) w[i] = fac*(1-z[i])/(w[i]*w[i]);
152 w[0] *= (beta + one);
159 template <
class Scalar>
168 Scalar fac, one = 1.0, two = 2.0, apb = alpha + beta;
177 for(i = 0; i < np; ++i) w[i] = fac*(1+z[i])/(w[i]*w[i]);
178 w[np-1] *= (alpha + one);
185 template <
class Scalar>
194 Scalar fac, one = 1.0, apb = alpha + beta, two = 2.0;
204 for(i = 0; i < np; ++i) w[i] = fac/(w[i]*w[i]);
205 w[0] *= (beta + one);
206 w[np-1] *= (alpha + one);
213 template <
class Scalar>
217 Scalar one = 1.0, two = 2.0;
226 pd = (Scalar *)malloc(np*
sizeof(Scalar));
229 for (i = 0; i < np; i++){
230 for (j = 0; j < np; j++){
234 D[i*np+j] = pd[i]/(pd[j]*(z[i]-z[j]));
236 D[i*np+j] = (alpha - beta + (alpha + beta + two)*z[j])/
237 (two*(one - z[j]*z[j]));
246 template <
class Scalar>
255 Scalar one = 1.0, two = 2.0;
258 pd = (Scalar *)malloc(np*
sizeof(Scalar));
263 for(i = 1; i < np; ++i) pd[i] *= (1+z[i]);
265 for (i = 0; i < np; i++) {
266 for (j = 0; j < np; j++){
269 D[i*np+j] = pd[i]/(pd[j]*(z[i]-z[j]));
272 D[i*np+j] = -(np + alpha + beta + one)*(np - one)/
275 D[i*np+j] = (alpha - beta + one + (alpha + beta + one)*z[j])/
276 (two*(one - z[j]*z[j]));
286 template <
class Scalar>
295 Scalar one = 1.0, two = 2.0;
298 pd = (Scalar *)malloc(np*
sizeof(Scalar));
302 for(i = 0; i < np-1; ++i) pd[i] *= (1-z[i]);
306 for (i = 0; i < np; i++) {
307 for (j = 0; j < np; j++){
310 D[i*np+j] = pd[i]/(pd[j]*(z[i]-z[j]));
313 D[i*np+j] = (np + alpha + beta + one)*(np - one)/
316 D[i*np+j] = (alpha - beta - one + (alpha + beta + one)*z[j])/
317 (two*(one - z[j]*z[j]));
327 template <
class Scalar>
336 Scalar one = 1.0, two = 2.0;
339 pd = (Scalar *)malloc(np*
sizeof(Scalar));
344 for(i = 1; i < np-1; ++i) pd[i] *= (one-z[i]*z[i]);
348 for (i = 0; i < np; i++) {
349 for (j = 0; j < np; j++){
352 D[i*np+j] = pd[i]/(pd[j]*(z[i]-z[j]));
355 D[i*np+j] = (alpha - (np-1)*(np + alpha + beta))/(two*(beta+ two));
357 D[i*np+j] =-(beta - (np-1)*(np + alpha + beta))/(two*(alpha+ two));
359 D[i*np+j] = (alpha - beta + (alpha + beta)*z[j])/
360 (two*(one - z[j]*z[j]));
370 template <
class Scalar>
372 const int np,
const Scalar alpha,
const Scalar beta)
375 Scalar zi, dz, p, pd, h;
379 if (std::abs(dz) < INTREPID_TOL)
return 1.0;
389 template <
class Scalar>
391 const int np,
const Scalar alpha,
const Scalar beta)
394 Scalar zi, dz, p, pd, h;
398 if (std::abs(dz) < INTREPID_TOL)
return 1.0;
403 h = (1.0 + zi)*pd + p;
405 h = (1.0 + z )*p/(h*dz);
411 template <
class Scalar>
413 const int np,
const Scalar alpha,
const Scalar beta)
416 Scalar zi, dz, p, pd, h;
420 if (std::abs(dz) < INTREPID_TOL)
return 1.0;
425 h = (1.0 - zi)*pd - p;
427 h = (1.0 - z )*p/(h*dz);
433 template <
class Scalar>
435 const int np,
const Scalar alpha,
const Scalar beta)
437 Scalar one = 1., two = 2.;
438 Scalar zi, dz, p, pd, h;
442 if (std::abs(dz) < INTREPID_TOL)
return 1.0;
447 h = (one - zi*zi)*pd - two*zi*p;
449 h = (one - z*z)*p/(h*dz);
455 template <
class Scalar>
457 const int mz,
const Scalar alpha,
const Scalar beta){
462 for (i = 0; i < mz; ++i) {
464 for (j = 0; j < nz; ++j) {
483 template <
class Scalar>
485 const int mz,
const Scalar alpha,
const Scalar beta)
490 for (i = 0; i < mz; i++) {
492 for (j = 0; j < nz; j++) {
511 template <
class Scalar>
513 const int mz,
const Scalar alpha,
const Scalar beta)
518 for (i = 0; i < mz; i++) {
520 for (j = 0; j < nz; j++) {
539 template <
class Scalar>
541 const int mz,
const Scalar alpha,
const Scalar beta)
546 for (i = 0; i < mz; i++) {
548 for (j = 0; j < nz; j++) {
567 template <
class Scalar>
570 jacobfd (
const int np,
const Scalar *z, Scalar *poly_in, Scalar *polyd,
571 const int n,
const Scalar alpha,
const Scalar beta)
573 const Scalar zero = 0.0, one = 1.0, two = 2.0;
581 for (
int i = 0; i < np; ++i) {
586 for (
int i = 0; i < np; ++i) {
593 for (
int i = 0; i < np; ++i) {
594 poly_in[i] = 0.5*(alpha - beta + (alpha + beta + two)*z[i]);
598 for (
int i = 0; i < np; ++i) {
599 polyd[i] = 0.5*(alpha + beta + two);
605 Scalar apb = alpha + beta;
606 Scalar *poly, *polyn1,*polyn2;
609 polyn1 = (Scalar *)malloc(2*np*
sizeof(Scalar));
614 polyn1 = (Scalar *)malloc(3*np*
sizeof(Scalar));
619 for (
int i = 0; i < np; ++i) {
621 polyn1[i] = 0.5*(alpha - beta + (alpha + beta + two)*z[i]);
624 for (
int k = 2; k <= n; ++k) {
625 a1 = two*k*(k + apb)*(two*k + apb - two);
626 a2 = (two*k + apb - one)*(alpha*alpha - beta*beta);
627 a3 = (two*k + apb - two)*(two*k + apb - one)*(two*k + apb);
628 a4 = two*(k + alpha - one)*(k + beta - one)*(two*k + apb);
634 for (
int i = 0; i < np; ++i) {
635 poly [i] = (a2 + a3*z[i])*polyn1[i] - a4*polyn2[i];
636 polyn2[i] = polyn1[i];
637 polyn1[i] = poly [i];
642 a1 = n*(alpha - beta);
643 a2 = n*(two*n + alpha + beta);
644 a3 = two*(n + alpha)*(n + beta);
645 a4 = (two*n + alpha + beta);
646 a1 /= a4; a2 /= a4; a3 /= a4;
649 for (
int i = 0; i < np; ++i) {
650 polyd[i] = (a1- a2*z[i])*poly[i] + a3*polyn2[i];
651 polyd[i] /= (one - z[i]*z[i]);
660 template <
class Scalar>
662 const Scalar alpha,
const Scalar beta)
667 for(i = 0; i < np; ++i) polyd[i] = 0.0;
671 for(i = 0; i < np; ++i) polyd[i] *= 0.5*(alpha + beta + (Scalar)n + one);
677 template <
class Scalar>
680 Scalar dth = M_PI/(2.0*(Scalar)n);
681 Scalar poly,pder,rlast=0.0;
683 Scalar one = 1.0, two = 2.0;
688 for(k = 0; k < n; ++k){
689 r = -std::cos((two*(Scalar)k + one) * dth);
690 if(k) r = 0.5*(r + rlast);
695 for(i = 0, sum = 0.0; i < k; ++i) sum += one/(r - z[i]);
697 delr = -poly / (pder - sum * poly);
699 if( std::abs(delr) < INTREPID_TOL )
break;
708 template <
class Scalar>
711 Scalar apb, apbi,a2b2;
717 b = (Scalar *) malloc(n*
sizeof(Scalar));
724 a[0] = (beta-alpha)/apbi;
725 b[0] = std::sqrt(4.0*(1.0+alpha)*(1.0+beta)/((apbi+1.0)*apbi*apbi));
727 a2b2 = beta*beta-alpha*alpha;
728 for(i = 1; i < n-1; ++i){
729 apbi = 2.0*(i+1) + apb;
730 a[i] = a2b2/((apbi-2.0)*apbi);
731 b[i] = std::sqrt(4.0*(i+1)*(i+1+alpha)*(i+1+beta)*(i+1+apb)/
732 ((apbi*apbi-1)*apbi*apbi));
737 if (n>1) a[n-1] = a2b2/((apbi-2.0)*apbi);
747 template <
class Scalar>
750 Scalar s,r,p,g,f,dd,c,b;
755 for (m=l;m<n-1;m++) {
756 dd=std::abs(d[m])+std::abs(d[m+1]);
757 if (std::abs(e[m])+dd == dd)
break;
761 TEUCHOS_TEST_FOR_EXCEPTION((1),
763 ">>> ERROR (IntrepidPolylib): Too many iterations in TQLI.");
765 g=(d[l+1]-d[l])/(2.0*e[l]);
766 r=std::sqrt((g*g)+1.0);
768 g=d[m]-d[l]+e[l]/(g+((g)<0 ? -std::abs(r) : std::abs(r)));
771 for (i=m-1;i>=l;i--) {
774 if (std::abs(f) >= std::abs(g)) {
776 r=std::sqrt((c*c)+1.0);
781 r=std::sqrt((s*s)+1.0);
786 r=(d[i]-g)*s+2.0*c*b;
799 for(i = 0; i < n-1; ++i){
802 for(l = i+1; l < n; ++l)
813 template <
class Scalar>
817 if (x == -0.5) gamma = -2.0*std::sqrt(M_PI);
818 else if (!x)
return gamma;
819 else if ((x-(
int)x) == 0.5){
823 gamma = std::sqrt(M_PI);
829 else if ((x-(
int)x) == 0.0){
839 TEUCHOS_TEST_FOR_EXCEPTION((1),
840 std::invalid_argument,
841 ">>> ERROR (IntrepidPolylib): Argument is not of integer or half order.");
static void Dgrjm(Scalar *D, const Scalar *z, const int np, const Scalar alpha, const Scalar beta)
Compute the Derivative Matrix and its transpose associated with the Gauss-Radau-Jacobi zeros with a z...
static void Imgj(Scalar *im, const Scalar *zgj, const Scalar *zm, const int nz, const int mz, const Scalar alpha, const Scalar beta)
Interpolation Operator from Gauss-Jacobi points to an arbitrary distribution at points zm...
static Scalar hgrjp(const int i, const Scalar z, const Scalar *zgrj, const int np, const Scalar alpha, const Scalar beta)
Compute the value of the i th Lagrangian interpolant through the np Gauss-Radau-Jacobi points zgrj at...
static void zwgrjp(Scalar *z, Scalar *w, const int np, const Scalar alpha, const Scalar beta)
Gauss-Radau-Jacobi zeros and weights with end point at z=1.
static void TriQL(const int n, Scalar *d, Scalar *e)
QL algorithm for symmetric tridiagonal matrix.
#define INTREPID_POLYLIB_STOP
Maximum number of iterations in polynomial defalation routine Jacobz.
static Scalar hglj(const int i, const Scalar z, const Scalar *zglj, const int np, const Scalar alpha, const Scalar beta)
Compute the value of the i th Lagrangian interpolant through the np Gauss-Lobatto-Jacobi points zglj ...
static void zwglj(Scalar *z, Scalar *w, const int np, const Scalar alpha, const Scalar beta)
Gauss-Lobatto-Jacobi zeros and weights with end point at z=-1,1.
static Scalar hgj(const int i, const Scalar z, const Scalar *zgj, const int np, const Scalar alpha, const Scalar beta)
Compute the value of the i th Lagrangian interpolant through the np Gauss-Jacobi points zgj at the ar...
static void zwgrjm(Scalar *z, Scalar *w, const int np, const Scalar alpha, const Scalar beta)
Gauss-Radau-Jacobi zeros and weights with end point at z=-1.
static Scalar hgrjm(const int i, const Scalar z, const Scalar *zgrj, const int np, const Scalar alpha, const Scalar beta)
Compute the value of the i th Lagrangian interpolant through the np Gauss-Radau-Jacobi points zgrj at...
static void JacZeros(const int n, Scalar *a, const Scalar alpha, const Scalar beta)
Zero determination through the eigenvalues of a tridiagonal matrix from the three term recursion rela...
static void jacobd(const int np, const Scalar *z, Scalar *polyd, const int n, const Scalar alpha, const Scalar beta)
Calculate the derivative of Jacobi polynomials.
static void Dgrjp(Scalar *D, const Scalar *z, const int np, const Scalar alpha, const Scalar beta)
Compute the Derivative Matrix associated with the Gauss-Radau-Jacobi zeros with a zero at z=1...
static void Imgrjm(Scalar *im, const Scalar *zgrj, const Scalar *zm, const int nz, const int mz, const Scalar alpha, const Scalar beta)
Interpolation Operator from Gauss-Radau-Jacobi points (including z=-1) to an arbitrary distrubtion at...
static void jacobfd(const int np, const Scalar *z, Scalar *poly_in, Scalar *polyd, const int n, const Scalar alpha, const Scalar beta)
Routine to calculate Jacobi polynomials, , and their first derivative, .
static void Jacobz(const int n, Scalar *z, const Scalar alpha, const Scalar beta)
Calculate the n zeros, z, of the Jacobi polynomial, i.e. .
static void Dgj(Scalar *D, const Scalar *z, const int np, const Scalar alpha, const Scalar beta)
Compute the Derivative Matrix and its transpose associated with the Gauss-Jacobi zeros.
static void Dglj(Scalar *D, const Scalar *z, const int np, const Scalar alpha, const Scalar beta)
Compute the Derivative Matrix associated with the Gauss-Lobatto-Jacobi zeros.
static void zwgj(Scalar *z, Scalar *w, const int np, const Scalar alpha, const Scalar beta)
Gauss-Jacobi zeros and weights.
static void Imglj(Scalar *im, const Scalar *zglj, const Scalar *zm, const int nz, const int mz, const Scalar alpha, const Scalar beta)
Interpolation Operator from Gauss-Lobatto-Jacobi points to an arbitrary distrubtion at points zm...
static Scalar gammaF(const Scalar x)
Calculate the Gamma function , , for integer values x and halves.
#define jacobz(n, z, alpha, beta)
zero determination using Newton iteration with polynomial deflation
static void Imgrjp(Scalar *im, const Scalar *zgrj, const Scalar *zm, const int nz, const int mz, const Scalar alpha, const Scalar beta)
Interpolation Operator from Gauss-Radau-Jacobi points (including z=1) to an arbitrary distrubtion at ...