// g05td Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.IO; namespace NagDotNetExamples { public class G05TDE { static void Main(String[] args) { StartExample(); } public static void StartExample() { try { const int np=11; const int mseed=1; const int n=20; int genid, i, ip1, itype, subid; double[] p = new double[np] {0.010e0, 0.020e0, 0.040e0, 0.080e0, 0.20e0, 0.30e0, 0.20e0, 0.080e0, 0.040e0, 0.020e0, 0.010e0}; double[] r = new double[10+(int)Math.Ceiling(1.4*np)]; int[] seed = new int[mseed]; int[] x = new int[n]; int ifail; Console.WriteLine("g05td Example Program Results"); Console.WriteLine("");Console.WriteLine(""); // Set the lowest value for the distribution ip1 = -5; // P is a PDF itype = 1; // Initialise the seed seed[0] = 1762543; // genid and subid identify the base generator genid = 1; subid = 1; // Initialise the generator to a repeatable sequence G05.G05State g05State = new G05.G05State(genid, subid, seed, out ifail); if (ifail != 0) { Console.WriteLine("** Generator initialisation failed with ifail = {0,5}", ifail); goto L20; } // Generate the variates // Choose mode = 2 G05.g05td(2, n, p, np, ip1, itype,r, g05State, x, out ifail); if (ifail != 0) { Console.WriteLine("** g05td failed with ifail = {0,5}", ifail); goto L20; } // Display the variates for (i = 1 ; i <= n ; i++) { Console.WriteLine(" {0,5}", x[i - 1]); } Console.WriteLine(""); // L20: ; // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } } }