// g02aa Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G02AAE { static void Main(String[] args) { StartExample(); } public static void StartExample() { try { double errtol, nrmgrd; int feval, i, iter, j, maxit, maxits, n; int ifail; Console.WriteLine("g02aa Example Program Results"); Console.WriteLine(""); // // Set up matrix G n = 4; double[,] g = new double[n, n]; double[,] x = new double[n, n]; for (j = 1; j <= n; j++) { for (i = 1; i <= n; i++) { g[i - 1, j - 1] = 0.0; } g[j - 1, j - 1] = 2.00e0; } for (j = 2; j <= n; j++) { g[j - 1 - 1, j - 1] = -1.00e0; g[j - 1, j - 1 - 1] = -1.00e0; } // // Set up method parameters errtol = 1.00e-7; maxits = 200; maxit = 10; // G02.g02aa(g, n, errtol, maxits, maxit, x, out iter, out feval, out nrmgrd, out ifail); // if (ifail == 0) { Console.WriteLine(" {0}", " Nearest Correlation Matrix\r\n"); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { Console.Write(" {0,11:f5}{1}", x[i - 1, j - 1],j%4==0? "\n":""); } } Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("{0}{1,11}", " Number of Newton steps taken:", iter); Console.WriteLine("{0}{1,9}", " Number of function evaluations:", feval); if (nrmgrd > errtol) { Console.WriteLine("{0}{1,11:e3}", " Norm of gradient of last Newton step:", nrmgrd); } } else { Console.WriteLine("** g02aa failed with ifail = {0,5}", ifail); } Console.WriteLine(""); // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }