// f08fa Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class F08FAE { static string datafile = "ExampleData/f08fae.d"; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { DataReader sr = new DataReader(datafile); double eerrbd, eps; int i, info, j, n; // Skip heading in data file sr.Reset(); sr.Reset(); n = int.Parse(sr.Next()); double[,] a = new double[n, n]; double[] rcondz = new double[n]; double[] w = new double[n]; double[] zerrbd = new double[n]; int ifail; Console.WriteLine("f08fa Example Program Results"); Console.WriteLine(""); if (n > 0) { // // Read the upper triangular part of the matrix A from data file // 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); } } // // Solve the symmetric eigenvalue problem // F08.f08fa("Vectors", "Upper", n, a, w, out info); if (info < 0) { return; } // if (info == 0) { // // Print solution // Console.WriteLine(" {0}", "Eigenvalues"); for (j = 1; j <= n; j++) { Console.Write(" {0,8:f4}", w[j - 1]); } Console.WriteLine(""); // X04.x04ca("General", "", n, n, a, "Eigenvectors", out ifail); // // Get the machine precision, eps and compute the approximate // error bound for the computed eigenvalues. Note that for // the 2-norm, max( abs(w[i-1]) ) = norm(a), and since the // eigenvalues are returned in ascending order // max( abs(w[i-1]) ) = max( abs(w[0]), abs(w[n-1])) // eps = X02.x02aj(); eerrbd = eps * Math.Max(Math.Abs(w[0]), Math.Abs(w[n - 1])); // // Call f08fl to estimate reciprocal condition // numbers for the eigenvectors // F08.f08fl("Eigenvectors", n, n, w, rcondz, out info); // // Compute the error estimates for the eigenvectors // for (i = 1; i <= n; i++) { zerrbd[i - 1] = eerrbd / rcondz[i - 1]; } // // Print the approximate error bounds for the eigenvalues // and vectors // Console.WriteLine(""); Console.WriteLine(" {0}", "Error estimate for the eigenvalues"); Console.WriteLine(" {0,11:e1}", eerrbd); Console.WriteLine(""); Console.WriteLine(" {0}", "Error estimates for the eigenvectors"); for (i = 1; i <= n; i++) { Console.Write(" {0, 11:e1}", zerrbd[i - 1]); } Console.WriteLine(); } else { Console.WriteLine(" {0}{1,4}", "Failure in DSYEV. INFO =", info); } // // Print workspace information // } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }