// g02hf Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G02HFE { static string datafile = "ExampleData/g02hfe.d"; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { G02.G02HF_PSI psiG02HF = new G02.G02HF_PSI(psi); G02.G02HF_PSP pspG02HF = new G02.G02HF_PSP(psp); DataReader sr = new DataReader(datafile); double sigma = 0.0; int i, indc, indw, j, k, m, n; int ifail; Console.WriteLine("g02hf 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[,] c = new double[m, m]; double[] rs = new double[n]; double[] wgt = new double[n]; double[,] x = new double[n, m]; double[] diag_d = new double[n]; double[] diag_p = new double[n]; Console.WriteLine(" "); 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 sigma sr.Reset(); sigma = double.Parse(sr.Next(), CultureInfo.InvariantCulture); // Read in weights and residuals for (i = 1; i <= n; i++) { sr.Reset(); wgt[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); rs[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } // Set parameters for Schweppe type regression indw = 1; indc = 1; // G02.g02hf(psiG02HF, pspG02HF, indw, indc, sigma, n, m, x, rs, wgt, c, diag_d, diag_p, out ifail); // if (ifail == 0) { Console.Write(" {0}", "Covariance matrix\n"); for (j = 1; j <= m; j++) { for (k = 1; k <= m; k++) { Console.Write(" {0,8:f4}", c[j - 1, k - 1]); } Console.WriteLine(" "); } } else { Console.WriteLine(" "); Console.WriteLine("** g02hf failed with ifail = {0,5}", ifail); } } // } catch (Exception e) { Console.WriteLine(e.Message); Console.Write( "Exception Raised"); } } // public static double psi(double t) { double psiValue = 0.0; double c = 1.5e0; if (t <= -c) { psiValue = -c; } else if (Math.Abs(t) < c) { psiValue = t; } else { psiValue = c; } return psiValue; } // public static double psp(double t) { double pspValue = 0.0; pspValue = 0.00e0; double c = 1.5e0; if (Math.Abs(t) < c) { pspValue = 1.00e0; } return pspValue; } } }