// g02hk Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G02HKE { static string datafile = "ExampleData/g02hke.d"; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { DataReader sr = new DataReader(datafile); double eps, tol; int i, j, k, l1, l2, m, maxit, n, nit, nitmon; int ifail; Console.WriteLine("g02hk Example Program Results"); // Skip heading in data file sr.Reset(); // Read in the dimensions of X sr.Reset(); n = int.Parse(sr.Next()); m = int.Parse(sr.Next()); double[] cov = new double[m*(m+1)/2]; double[] theta = new double[m]; double[,] x = new double[n, m]; if (n > 0 && m > 0 && m <=n) { // Read in the x matrix for (i = 1; i <= n; i++) { sr.Reset(); for (j = 1; j <= m; j++) { x[i - 1, j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } } // Read in value of eps sr.Reset(); eps = double.Parse(sr.Next(), CultureInfo.InvariantCulture); // Set up remaining parameters maxit = 100; tol = 0.50e-4; // Set nitmon to positive value for iteration monitoring nitmon = 0; // G02.g02hk(n, m, x, eps, cov, theta, maxit, nitmon, tol, out nit, out ifail); // if (ifail == 0) { Console.WriteLine(" "); Console.Write(" {0}{1,4}{2}", "g02hk required ", nit, " iterations to converge"); Console.WriteLine(" "); Console.WriteLine(" {0}", "Covariance matrix\n"); l2 = 0; for (j = 1; j <= m; j++) { l1 = l2 + 1; l2 = l2 + j; for (k = l1; k <= l2; k++) { Console.Write(" {0,10:f3}", cov[k - 1]); } Console.WriteLine(" "); } Console.WriteLine(" "); Console.WriteLine(" {0}", "THETA"); for (j = 1; j <= m; j++) { Console.WriteLine(" {0,10:f3}", theta[j - 1]); } } else { Console.WriteLine(" "); Console.WriteLine("** g02hk failed with ifail = {0,5}", ifail); } } // } catch (Exception e) { Console.WriteLine(e.Message); Console.Write( "Exception Raised"); } } } }