private static void mltply_test() //****************************************************************************80 // // Purpose: // // MLTPLY_TEST tests MLTPLY, which multiplies two Chebyshev series. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 24 September 2011 // // Author: // // John Burkardt // { int i; const int nf = 5; const int npl = 10; Console.WriteLine(""); Console.WriteLine("MLTPLY_TEST"); Console.WriteLine(" MLTPLY computes the product of two Chebyshev series."); Console.WriteLine(""); Console.WriteLine(" Multiply series for SIN(X) and COS(X)"); Console.WriteLine(" and compare with series for 1/2*SIN(2X)."); double[] x = Chebyshev.cheby(nf, npl, functn); double[] x1 = new double[npl]; double[] x2 = new double[npl]; for (i = 0; i < npl; i++) { x1[i] = x[i + 0 * npl]; x2[i] = x[i + 1 * npl]; x[i + 2 * npl] = 0.5 * x[i + 2 * npl]; } double[] x3 = ChebyshevSeries.mltply_new(x1, x2, npl); Console.WriteLine(""); Console.WriteLine(" Sin(x) Cos(x) 1/2*Sin(2x) RESULT"); Console.WriteLine(""); for (i = 0; i < npl; i++) { Console.WriteLine(" " + x[i + 0 * npl].ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + x[i + 1 * npl].ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + x[i + 2 * npl].ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + x3[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); } }
private static void cheby_test() //****************************************************************************80 // // Purpose: // // CHEBY_TEST tests CHEBY, which computes Chebyshev series. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 24 September 2011 // // Author: // // John Burkardt // { int i; const int nf = 5; const int npl = 10; Console.WriteLine(""); Console.WriteLine("CHEBY_TEST"); Console.WriteLine(" CHEBY computes the Chebyshev series for several functions."); double[] x = Chebyshev.cheby(nf, npl, functn); Console.WriteLine(""); Console.WriteLine(" Sin(x) Cos(x) Sin(2x) Cos(2x) X^5"); Console.WriteLine(""); for (i = 0; i < npl; i++) { string cout = ""; int j; for (j = 0; j < nf; j++) { cout += " " + x[i + j * npl].ToString(CultureInfo.InvariantCulture).PadLeft(14); } Console.WriteLine(cout); } }
private static void dfrnt_test() //****************************************************************************80 // // Purpose: // // DFRNT_TEST tests DFRNT, which computes the Chebyshev series of a derivative. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 24 September 2011 // // Author: // // John Burkardt // { int i; int j; const int nf = 5; const int npl = 10; Console.WriteLine(""); Console.WriteLine("DFRNT_TEST"); Console.WriteLine(" DFRNT computes the Chebyshev series for the derivative"); Console.WriteLine(" of several functions."); double[] x = Chebyshev.cheby(nf, npl, functn); double[] x2 = new double[npl]; for (j = 0; j < nf; j++) { for (i = 0; i < npl; i++) { x2[i] = x[i + j * npl]; } double[] x3 = ChebyshevSeries.dfrnt(x2, npl); for (i = 0; i < npl; i++) { x[i + j * npl] = x3[i]; } } Console.WriteLine(""); Console.WriteLine(" Chebyshev series for d/dx of:"); Console.WriteLine(""); Console.WriteLine(" Sin(x) Cos(x) Sin(2x) Cos(2x) X^5"); Console.WriteLine(""); for (i = 0; i < npl; i++) { string cout = ""; for (j = 0; j < nf; j++) { cout += " " + x[i + j * npl].ToString(CultureInfo.InvariantCulture).PadLeft(14); } Console.WriteLine(cout); } }
private static void edcheb_test() //****************************************************************************80 // // Purpose: // // EDCHEB_TEST tests EDCHEB, which evaluates the derivative of a Chebyshev series. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 24 September 2011 // // Author: // // John Burkardt // { int j; const int nf = 5; const int npl = 10; const int nx = 6; Console.WriteLine(""); Console.WriteLine("EDCHEB_TEST"); Console.WriteLine(" EDCHEB evaluates the derivative of a Chebyshev series."); double[] x = Chebyshev.cheby(nf, npl, functn); double[] x2 = new double[npl]; for (j = 0; j < nf; j++) { int i; for (i = 0; i < npl; i++) { x2[i] = x[i + j * npl]; } Console.WriteLine(""); switch (j) { case 0: Console.WriteLine(" Sin(x)"); break; case 1: Console.WriteLine(" Cos(x)"); break; case 2: Console.WriteLine(" Sin(2x)"); break; case 3: Console.WriteLine(" Cos(2x)"); break; case 4: Console.WriteLine(" x^5"); break; } Console.WriteLine(""); int k; for (k = 0; k < nx; k++) { double xval = 2.0 * k / (nx - 1) - 1.0; double[] fxj = functn_d(xval); double fval = ChebyshevSeries.edcheb(xval, x2, npl); Console.WriteLine(" " + xval.ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + fxj[j].ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + fval.ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); } } }