// e04ab Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class E04ABE { static void Main(String[] args) { StartExample(); } public static void StartExample() { E04.E04AB_FUNCT functE04AB = new E04.E04AB_FUNCT(funct); double a, b, e1, e2, f, x; int ifail, maxcal; Console.WriteLine("e04ab Example Program Results"); // e1 and e2 are set to zero so that E04.e04ab will reset them to // their default values e1 = 0.00e0; e2 = 0.00e0; // The minimum is known to lie in the range (3.5, 5.0) a = 3.50e0; b = 5.00e0; // Allow 30 calls of funct maxcal = 30; // try { E04.e04ab(functE04AB, ref e1, ref e2, ref a, ref b, ref maxcal, out x, out f, out ifail); // Console.WriteLine(""); if (ifail < 0) { Console.WriteLine(" ** e04ab returned with ifail = {0, 3}", ifail); } else if (ifail == 1) { Console.WriteLine(" {0}", "Parameter outside expected range"); } else { if (ifail == 2) { Console.WriteLine(" {0}", "Results after MAXCAL function evaluations are"); Console.WriteLine(""); } Console.WriteLine(" {0}{1,10:f8}{2}{3,10:f8}", "The minimum lies in the interval ", a, " to ", b); Console.WriteLine(" {0}{1,10:f8}{2}", "Its estimated position is ", x, ","); Console.WriteLine(" {0}{1,7:f4}", "where the function value is ", f); Console.WriteLine(" {0,2} {1}", maxcal, " function evaluations were required"); } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } // public static void funct(double xc, out double fc) { // Routine to evaluate F(x) at any point in (A, B) fc = Math.Sin(xc) / xc; } } }