40 #define KPI2 6.2831853071795864769252867665590057683943387987502
56 fpt_set set = fpt_init(1,lrint(ceil(log2((
double)N))),0U);
59 double *
alpha = malloc((N+2)*
sizeof(
double)),
60 *
beta = malloc((N+2)*
sizeof(
double)),
61 *
gamma = malloc((N+2)*
sizeof(
double));
64 alpha[0] =
beta[0] = 0.0;
71 for (k = 0; k <= N; k++)
73 alpha[k+1] = ((double)(2*k+1))/((
double)(k+1));
75 gamma[k+1] = -((double)(k))/((
double)(k+1));
80 "Computing a fast polynomial transform (FPT) and a fast discrete cosine \n"
81 "transform (DCT) to evaluate\n\n"
82 " f_j = a_0 P_0(x_j) + a_1 P_1(x_j) + ... + a_N P_N(x_j), j=0,1,...,N,\n\n"
83 "with N=%d, x_j = cos(j*pi/N), j=0,1,...N, the Chebyshev nodes, a_k,\n"
84 "k=0,1,...,N, random Fourier coefficients in [-1,1]x[-1,1]*I, and P_k,\n"
85 "k=0,1,...,N, the Legendre polynomials.",N
98 fpt_precompute(
set,0,alpha,
beta,
gamma,0,1000.0);
103 double _Complex *a = malloc((N+1)*
sizeof(
double _Complex));
104 double _Complex *b = malloc((N+1)*
sizeof(
double _Complex));
105 double *f = malloc((N+1)*
sizeof(
double _Complex));
108 const int NP1 = N + 1;
109 fftw_r2r_kind kind = FFTW_REDFT00;
110 fftw_plan p = fftw_plan_many_r2r(1, &NP1, 1, (
double*)b, NULL, 2, 1,
111 (
double*)f, NULL, 1, 1, &kind, 0U);
116 printf(
"\n2) Random Fourier coefficients a_k, k=0,1,...,N:\n");
117 for (k = 0; k <= N; k++)
119 a[k] = 2.0*nfft_drand48() - 1.0;
120 printf(
" a_%-2d = %+5.3lE\n",k,creal(a[k]));
125 fpt_trafo(
set,0,a,b,N,0U);
133 for (j = 1; j < N; j++)
142 printf(
"\n3) Function values f_j, j=1,1,...,M:\n");
143 for (j = 0; j <= N; j++)
144 printf(
" f_%-2d = %+5.3lE\n",j,f[j]);
153 fftw_destroy_plan(p);