// d01ar Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class D01ARE { static void Main(String[] args) { StartExample(); } public static void StartExample() { try { const int maxrul = 0; D01.D01AR_FUN f1D01AR = new D01.D01AR_FUN(f1); D01.D01AR_FUN f2D01AR = new D01.D01AR_FUN(f2); double a, absacc, acc, ans, b, relacc; int iparm, n; double[] alpha = new double[390]; int ifail; Console.WriteLine("d01ar Example Program Results"); relacc = 0.00e0; absacc = 1.00e-5; // Definite integral of f1(x) - no expansion iparm = 0; a = 0.00e0; b = 1.00e0; Console.WriteLine(""); Console.WriteLine(" {0}", "Definite integral of 4/(1+x*x) over (0,1)"); // D01.d01ar(a, b, f1D01AR, relacc, absacc, maxrul, iparm, out acc, out ans, out n, alpha, out ifail); // if (ifail != 0) { Console.WriteLine("** d01ar failed with ifail = {0,5}", ifail); if (ifail < 0) { goto L20; } } if (ifail <= 1) { Console.WriteLine(" {0}{1,9:f5}", "Estimated value of the integral =", ans); Console.WriteLine(" {0}{1,10:e2}", "Estimated absolute error =", acc); Console.WriteLine(" {0}{1,4}", "Number of points used =", n); } // Definite integral of f2(x) - with expansion iparm = 1; a = 1.00e0; b = 2.00e0; Console.WriteLine(""); Console.WriteLine(" {0}", "Definite integral of x**(1/8) over (1,2)"); // D01.d01ar(a, b, f2D01AR, relacc, absacc, maxrul, iparm, out acc, out ans, out n, alpha, out ifail); // if (ifail != 0) { Console.WriteLine("** d01ar failed with ifail = {0,5}", ifail); if (ifail < 0) { goto L20; } } if (ifail <= 1) { Console.WriteLine(" {0}{1,9:f5}", "Estimated value of the integral =", ans); Console.WriteLine(" {0}{1,10:e2}", "Estimated absolute error =", acc); Console.WriteLine(" {0}{1,4}", "Number of points used =", n); } // Indefinite integral of f2(x) iparm = 2; a = 1.20e0; b = 1.80e0; Console.WriteLine(""); Console.WriteLine(" {0}", "Indefinite integral of x**(1/8) over (1.2,1.8)"); // D01.d01ar(a, b, f2D01AR, relacc, absacc, maxrul, iparm, out acc, out ans, out n, alpha, out ifail); // Console.WriteLine(" {0}{1,9:f5}", "Estimated value of the integral =", ans); L20: ; // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } ; } // public static double f1(double x) { double f1Value = 0.0; f1Value = 4.00e0 / (1.00e0 + x * x); return f1Value; } public static double f2(double x) { double f2Value = 0.0; f2Value = Math.Pow(x, 0.1250e0); return f2Value; } } }