// e04pc Example Program Text // Mark 24 Release. NAG Copyright 2012. // C# version, NAG Copyright 2012 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class E04PCE { static string datafile = "ExampleData/e04pce.d"; // as a command line argument. It defaults to the named file specified below otherwise. // static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { DataReader sr = new DataReader(datafile); double tol = 0.0; int itype = 1; double rnorm; int i = 0, ifail = 0, lda = 0, lwork = 0, m = 0, n = 0, nfree = 0; double[,] a; double[] b; double[] lbnd; double[] ubnd; double[] w; double[] x; int[] indx; Console.WriteLine(" {0}", "E04PCF Example Program Results"); Console.WriteLine(""); // Skip heading in data file sr.Reset(); sr.Reset(); m = int.Parse(sr.Next()); n = int.Parse(sr.Next()); int j = 0; lda = (int)m; lwork = 4 * n; // allocate a = new double[lda, n]; b = new double[m]; w = new double[lwork]; lbnd = new double[n]; ubnd = new double[n]; x = new double[n]; indx = new int[n]; // allocate sr.Reset(); for (i = 1; i <= m; i++) { for (j = 1; j <= n; j++) { a[i - 1, j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } } sr.Reset(); for (j = 1; j <= m; j++) { b[j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } sr.Reset(); for (j = 1; j <= n; j++) { lbnd[j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } sr.Reset(); for (j = 1; j <= n; j++) { ubnd[j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } ifail = 0; E04.e04pc(itype, m, n, a, b, lbnd, ubnd, tol, x, out rnorm, out nfree, w, indx,out ifail); Console.WriteLine("Solution vector\n"); for (j = 1; j <= n; j++) { Console.WriteLine(" {0}" , x[j - 1]); } Console.WriteLine(""); Console.WriteLine("Dual Solution\n"); for (j = 1; j <= n; j++) { Console.WriteLine(" {0} ", w[j - 1]); } Console.WriteLine(" \n{0} {1} ", "Residual ", rnorm); Console.WriteLine(""); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }