// g05ym Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G05YME { static void Main(String[] args) { StartExample(); } public static void StartExample() { try { const int n=200; const int midim=8; const int ordrc=1; const int liref=32 * midim + 7; double sum, tmp, vsbl; int d, genid, i, idim, iskip, j; int[] iref = new int[liref]; int ifail; Console.WriteLine("g05ym Example Program Results"); idim = midim; double[,] quas = new double[idim, n]; // Skip the first few variates in the sequence iskip = 1000; // Initialise the Sobol generator genid = 1; G05.g05yl(genid, idim, iref, iskip, out ifail); if (ifail != 0) { Console.WriteLine("** g05yl 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,8:f4}", quas[j - 1 , i - 1]); } Console.WriteLine(""); } // L80: ; // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } } }