// d01ap Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class D01APE { public static int kount = 0, nof = 0; static void Main(String[] args) { StartExample(); } public static void StartExample() { try { const int lw = 800; D01.D01AP_G gD01AP = new D01.D01AP_G(g); double a, abserr, b, epsabs, epsrel, result; double[] alfa = new double[2] { 0.00e0, -0.50e0 }; double[] beta = new double[2] { 0.00e0, -0.50e0 }; double[] w = new double[lw]; int[] key = new int[2] { 2, 1 }; int subintvls; int ifail; Console.WriteLine("d01ap Example Program Results"); epsabs = 0.00e0; epsrel = 1.00e-04; a = 0.00e0; b = 1.00e0; for (nof = 1; nof <= 2; nof++) { kount = 0; // D01.d01ap(gD01AP, a, b, alfa[nof - 1], beta[nof - 1], key[nof - 1], epsabs, epsrel, out result, out abserr, w, out subintvls, out ifail); // if (ifail < 0) { Console.WriteLine(""); Console.WriteLine("** d01ap failed with ifail = {0,5}", ifail); goto L40; } Console.WriteLine(""); Console.WriteLine(" {0}{1,10:f4}", "a - lower limit of integration = ", a); Console.WriteLine(" {0}{1,10:f4}", "b - upper limit of integration = ", b); Console.WriteLine(" {0}{1,9:e2}", "epsabs - absolute accuracy requested = ", epsabs); Console.WriteLine(" {0}{1,9:e2}", "epsrel - relative accuracy requested = ", epsrel); Console.WriteLine(""); Console.WriteLine(" {0}{1,9:e2}", "ALFa - parameter in the weight function = ", alfa[nof - 1]); Console.WriteLine(" {0}{1,9:e2}", "BETa - parameter in the weight function = ", beta[nof - 1]); Console.WriteLine(" {0}{1,4}", "key - denotes which weight function is to be used = ", key[nof - 1]); Console.WriteLine(""); if (ifail != 0) { Console.WriteLine(" {0}{1,4}", "ifail = ", ifail); } if (ifail <= 3) { Console.WriteLine(" {0}{1,9:f5}", "result - approximation to the integral = ", result); Console.WriteLine(" {0}{1,9:e2}", "abserr - estimate of the absolute error = ", abserr); Console.WriteLine(" {0}{1,4}", "kount - number of function evaluations = ", kount); Console.WriteLine(" {0}{1,4}", "subintvls - number of subintervals used = ", subintvls); } } L40: ; // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } ; } // public static double g(double x) { double gValue = 0.0; double a, omega, pi; pi = Math.PI; kount = kount + 1; if (nof == 1) { a = 10.00e0 * pi; gValue = Math.Cos(a * x); } else { omega = 10.00e0; gValue = Math.Sin(omega * x); } return gValue; } } }