// g01nb Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G01NBE { static string datafile = "ExampleData/g01nbe.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 abserr, beta, eps, y0; int i, j, l1, l2, lmax, n; int ifail; Console.WriteLine("g01nb Example Program Results"); // Skip heading in data file sr.Reset(); sr.Reset(); beta = double.Parse(sr.Next(), CultureInfo.InvariantCulture); y0 = double.Parse(sr.Next(), CultureInfo.InvariantCulture); sr.Reset(); n = int.Parse(sr.Next()); l1 = int.Parse(sr.Next()); l2 = int.Parse(sr.Next()); if (n >=1 && l2 <= 12) { double[,] a = new double[n, n]; double[,] b = new double[n, n]; double[,] c = new double[n, n]; double[] ela = new double[n]; double[] emu = new double[n]; double[] rmom = new double[l2-l1+1]; double[,] sigma = new double[n, n]; // // Compute a, emu, and sigma for simple autoregression // for (i = 1 ; i <= n ; i++) { for (j = i ; j <= n ; j++) { a[j - 1 , i - 1] = 0.00e0; b[j - 1 , i - 1] = 0.00e0; } } for (i = 1 ; i <= n - 1 ; i++) { a[i + 1 - 1 , i - 1] = 0.50e0; b[i - 1 , i - 1] = 1.00e0; } emu[0] = y0 * beta; for (i = 1 ; i <= n - 1 ; i++) { emu[i + 1 - 1] = beta * emu[i - 1]; } sigma[0 , 0] = 1.00e0; for (i = 2 ; i <= n ; i++) { sigma[i - 1 , i - 1] = beta * beta * sigma[i - 1 - 1 , i - 1 - 1] + 1.00e0; } for (i = 1 ; i <= n ; i++) { for (j = i + 1 ; j <= n ; j++) { sigma[j - 1 , i - 1] = beta * sigma[j - 1 - 1 , i - 1]; } } eps = 0.00e0; // G01.g01nb("Ratio", "Mean", n, a, b, c, ela, emu, sigma, l1, l2, out lmax, rmom, out abserr, eps, out ifail); // if ((ifail == 0) || (ifail >= (6))) { Console.WriteLine(""); Console.WriteLine("{0}{1,3}{2}{3,6:f3}{4}{5,6:f3}"," N = ",n," BETA = ",beta," Y0 = ",y0); Console.WriteLine(""); Console.WriteLine(" {0}"," Moments"); Console.WriteLine(""); j = 0; for (i = l1 ; i <= lmax ; i++) { j = j + 1; Console.WriteLine("{0,3}{1,12:e3}",i,rmom[j - 1]); } } else { Console.WriteLine(""); Console.WriteLine("** g01nb failed with ifail = {0,5}", ifail); } } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } } }