// e04bb Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class E04BBE { static void Main(String[] args) { StartExample(); } public static void StartExample() { E04.E04BB_FUNCT functE04BB = new E04.E04BB_FUNCT(funct); double a, b, e1, e2, f, g, x; int ifail, maxcal; Console.WriteLine("e04bb Example Program Results"); // e1 and e2 are set to zero so that E04.e04bb 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.e04bb(functE04BB, ref e1, ref e2, ref a, ref b, ref maxcal, out x, out f, out g, out ifail); // Console.WriteLine(""); if (ifail < 0) { Console.WriteLine(" ** e04bb 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 calls of FUNCT 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}{1,8:e1}{2}", "and the gradient is ", g, " (machine dependent)"); Console.WriteLine(" {0,2}{1}", maxcal, " calls of FUNCT were required"); } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } // public static void funct(double xc, out double fc, out double gc) { // Routine to evaluate F(x) and dF/dx at any point in (A, B) fc = Math.Sin(xc) / xc; gc = (Math.Cos(xc) - fc) / xc; } } }