// g02hm Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G02HME { static string datafile = "ExampleData/g02hme.d"; static double[] ruser = new double[2]; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { G02.G02HM_UCV ucvG02HM = new G02.G02HM_UCV(ucv); DataReader sr = new DataReader(datafile); double bd, bl, tol; int i, indm, j, k, l1, l2, m, maxit, mm, n, nit, nitmon; int ifail; Console.WriteLine("g02hm 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[] a = new double[m*(m+1)/2]; double[] cov = new double[m*(m+1)/2]; double[] theta = new double[m]; double[] wt = new double[n]; 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 the initial value of A mm = ((m + 1) * m) / 2; sr.Reset(); for (j = 1; j <= mm; j++) { a[j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } // Read in the initial value of theta sr.Reset(); for (j = 1; j <= m; j++) { theta[j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } // Read in the values of the parameters of the ucv functions sr.Reset(); ruser[0] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); ruser[1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); // Set the values remaining parameters indm = 1; bl = 0.90e0; bd = 0.90e0; maxit = 50; tol = 0.50e-4; // Change nitmon to a positive value if monitoring information // is required nitmon = 0; // G02.g02hm(ucvG02HM, indm, n, m, x, cov, a, wt, theta, bl, bd, maxit, nitmon, tol, out nit, out ifail); // if (ifail == 0) { Console.WriteLine(" "); Console.Write(" {0}{1,4}{2}", "g02hm required ", nit, " iterations to converge"); Console.WriteLine(" "); Console.Write(" {0}", "Robust covariance matrix"); Console.WriteLine(" "); 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}", "Robust estimates of THETA"); for (j = 1; j <= m; j++) { Console.WriteLine(" {0,10:f3}", theta[j - 1]); } } else { Console.WriteLine(" "); Console.WriteLine("** g02hm failed with ifail = {0,5}", ifail); } } // } catch (Exception e) { Console.WriteLine(e.Message); Console.Write( "Exception Raised"); } } public static void ucv(double t, out double u, out double w) { // u function double cu, cw, t2; cu = ruser[0]; u = 1.00e0; if (t != 0) { t2 = t * t; if (t2 > cu) { u = cu / t2; } } // w function cw = ruser[1]; if (t > cw) { w = cw / t; } else { w = 1.00e0; } } } }