// f01ef Example Program Text // Mark 25 Release. NAG Copyright 2013. // C# version, NAG Copyright 2012 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class F01EFE { public static void f(ref int iflag, int n, double[] x, double[] fx) { int j = 0; for (j = 1; j <= n; j++) { fx[j - 1] = Math.Cos(x[j - 1]); } } // Specify data file as a command line argument. // It defaults to the named file specified below otherwise. static string datafile = "ExampleData/f01efe.d"; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { F01.F01EF_F fF01EFF = new F01.F01EF_F(f); DataReader sr = new DataReader(datafile); // f01ef Example Main Program int i = 0, ierr = 0, ifail = 0, iflag = 0, lda = 0, n = 0; string uplo = ""; double[] ruser = new double[1]; int[] iuser = new int[1]; Console.WriteLine(" {0}", "F01EFF Example Program Results"); Console.WriteLine(""); // Skip heading in data file sr.Reset(); sr.Reset(); n = int.Parse(sr.Next()); sr.Reset(); uplo = sr.Next(); int j = 0; lda = (int)n; double[,] a = new double[lda,n]; // allocate // Read A from data file if ((uplo == "U") || (uplo == "u")) { sr.Reset(); for (i = 1; i <= n; i++) { for (j = i; j <= n; j++) { a[i - 1, j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } } } else { sr.Reset(); for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) { a[i - 1, j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } } } // Find f( A ) ifail = 0; F01.f01ef(uplo, n, a, fF01EFF, out iflag, out ifail); // Print solution ierr = 0; X04.x04ca(uplo, "N", n, n, a, "Symmetric f(A)", out ierr); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }