// g05yn Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G05YNE { const int mn=200; const int midim=8; const int ordrc=1; const int ldquas=midim; const int tdquas=mn; const int liref=32 * midim + 7; const int mseed=1; static void Main(String[] args) { StartExample(); } public static void StartExample() { try { double sum, tmp, vsbl; int d, i, idim, iskip, j, n, nsdigi, pgenid, psubid, stype; int[] iref = new int[liref]; int[] seed = new int[mseed]; int ifail; Console.WriteLine("g05yn Example Program Results"); // Initialise the psuedo-random generator used in the // scrambling to a repeatable sequence seed[0] = 1762543; pgenid = 1; psubid = 1; G05.G05State g05State = new G05.G05State(pgenid, psubid, seed, out ifail); if (ifail != 0) { Console.WriteLine("** Generator initialisation failed with ifail = {0,5}", ifail); goto L80; } // Problem size idim = 8; n = mn; double[,] quas = new double[idim, n]; // Skip the first few variates in the sequence iskip = 1000; // Initialise the Sobol generator // Use Owen type scrambling stype = 1; // Use the default value for nsdigi nsdigi = 0; // Call the initialiser for the quasi-random sequence G05.g05yn(pgenid, stype, idim, iref, iskip, nsdigi, g05State, out ifail); if (ifail != 0) { Console.WriteLine("** g05yn failed with ifail = {0,5}", ifail); goto L80; } // Generate N quasi-random variates G05.g05ym(n, ordrc, quas, iref, out ifail); if (ifail != 0) { Console.WriteLine("** g05ym failed with ifail = {0,5}", ifail); goto L80; } // Evaluate the function, and sum sum = 0.00e0; for (i = 1 ; i <= n ; i++) { tmp = 1.00e0; for (d = 1 ; d <= idim ; d++) { tmp = tmp * Math.Abs(4.00e0 * quas[d - 1 , i - 1] - 2.00e0); } sum = sum + tmp; } // Convert sum to mean value vsbl = sum / (double)n; Console.WriteLine(" "); Console.WriteLine(" {0}{1,8:f4}","Value of integral = ",vsbl); // Dump the first 10 variates Console.WriteLine(" "); Console.WriteLine(" {0}","First 10 variates"); Console.WriteLine(""); for (i = 1 ; i <= 10 ; i++) { Console.Write(" {0,3} ", i); for (j = 1 ; j <= idim ; j++) { Console.Write(" {0,6:f4}", quas[j - 1 , i - 1]); } Console.WriteLine(""); } // L80: ; // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } } }