// g05rz Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G05RZE { static void Main(String[] args) { StartExample(); } public static void StartExample() { try { const int mseed=1; int genid, i, j, m, mode, n, subid; int[] seed = new int[mseed]; int ifail; Console.WriteLine("g05rz Example Program Results"); Console.WriteLine(""); // Set the number of variables and variates m = 4; n = 10; double[] r = new double[m*(m+1)+1]; double[,] x = new double[n, m]; double[] xmu = new double[m]; double[,] c = new double[m, m]; // Input the upper triangle portion of the covariance matrix c[0 , 0] = 1.690e0; c[0 , 1] = 0.390e0; c[0 , 2] = -1.860e0; c[0 , 3] = 0.070e0; c[1 , 0] = 0.390e0; c[1 , 1] = 98.010e0; c[1 , 2] = -7.070e0; c[1 , 3] = -0.710e0; c[2 , 0] = -1.860e0; c[2 , 1] = -7.070e0; c[2 , 2] = 11.560e0; c[2 , 3] = 0.030e0; c[3 , 0] = 0.070e0; c[3, 1] = -0.710e0; c[3 , 2] = 0.030e0; c[3 , 3] = 0.010e0; // Input the means xmu[0] = 1.00e0; xmu[1] = 2.00e0; xmu[2] = -3.00e0; xmu[3] = 0.00e0; // 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 L40; } // Set up reference vector and generate N numbers // Choose mode = 2 mode = 2; G05.g05rz(mode, n, m, xmu, c,r, g05State, x, out ifail); if (ifail != 0) { Console.WriteLine("** g05rz failed with ifail = {0,5}", ifail); goto L40; } // Display the variates for (i = 1 ; i <= n ; i++) { for (j = 1 ; j <= m ; j++) { Console.Write(" {0,8:f4} ", x[i - 1 , j - 1]); } Console.WriteLine(""); } // L40: ; // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } } }