// f08wp Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class F08WPE { static string datafile = "ExampleData/f08wpe.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 abnorm, abnrm, bbnrm, eps, erbnd, rcnd, small, tol; int i, ihi, ilo, info, j, n; Console.WriteLine("f08wp Example Program Results"); // Skip heading in data file sr.Reset(); sr.Reset(); n = int.Parse(sr.Next()); Complex[,] a = new Complex[n, n]; Complex[] alpha = new Complex[n]; Complex[,] b = new Complex[n, n]; Complex[] beta = new Complex[n]; Complex[,] dummy = new Complex[1, 1]; Complex[,] vr = new Complex[n, n]; double[] lscale = new double[n]; double[] rconde = new double[n]; double[] rcondv = new double[n]; double[] rscale = new double[n]; if (n > 1) { // // Read in the matrices A and B // sr.Reset(); for (i = 1 ; i <= n ; i++) { for (j = 1 ; j <= n ; j++) { a[i - 1 , j - 1] = Complex.Parse(sr.Next()); } } sr.Reset(); for (i = 1 ; i <= n ; i++) { for (j = 1 ; j <= n ; j++) { b[i - 1 , j - 1] = Complex.Parse(sr.Next()); } } // // Solve the generalized eigenvalue problem // F08.f08wp("Balance", "No vectors (left)", "Vectors (right)", "Both reciprocal condition numbers", n, a, b, alpha, beta, dummy, vr, out ilo, out ihi, lscale, rscale, out abnrm, out bbnrm, rconde, rcondv, out info); // if (info > 0) { Console.WriteLine(""); Console.WriteLine(" {0}{1,4}","Failure in ZGGEVX. INFO =",info); } else { // // Compute the machine precision, the safe range parameter // small and sqrt(abnrm**2+bbnrm**2) // eps = X02.x02aj(); small = X02.x02am(); abnorm = F06.f06bn(abnrm, bbnrm); tol = eps * abnorm; // // Print out eigenvalues and vectors and associated condition // number and bounds // for (j = 1 ; j <= n ; j++) { // // Print out information on the jth eigenvalue // Console.WriteLine(""); if (((Complex.Abs(alpha[j - 1])) * small) >= (Complex.Abs(beta[j - 1]))) { Console.WriteLine(" {0}{1,2}{2}{3}\n {4}{5,2}{6}({7,11:e4},{8,11:e4}){9}{10,2}{11}(","Eigenvalue(",j,")"," is numerically infinite or undetermined","ALPHA(",j,") = ",alpha[j - 1],", BETA(",j,") = ",beta[j - 1]); } else { Console.WriteLine(" {0}{1,2}{2}{3,11:e4}","Eigenvalue(",j,") = ",alpha[j - 1] / beta[j - 1]); } rcnd = rconde[j - 1]; Console.WriteLine(""); Console.WriteLine(" {0}{1,8:e1}","Reciprocal condition number = ",rcnd); if (rcnd > 0.00e0) { erbnd = tol / rcnd; Console.WriteLine(" {0}{1,8:e1}","Error bound = ",erbnd); } else { Console.WriteLine(" {0}","Error bound is infinite"); } // // Print out information on the jth eigenvector // Console.WriteLine(""); Console.Write(" {0}", "Eigenvector("); Console.Write(" {0}", j); Console.WriteLine(" {0}", ")"); for (i = 1 ; i <= n ; i++) { Console.Write("{0, 11:e4}{1}", vr[i - 1 , j - 1], i%3==0?"\n":""); } Console.WriteLine(); rcnd = rcondv[j - 1]; Console.WriteLine(""); Console.WriteLine(" {0}{1,8:e1}","Reciprocal condition number = ",rcnd); if (rcnd > 0.00e0) { erbnd = tol / rcnd; Console.WriteLine(" {0}{1,8:e1}","Error bound = ",erbnd); } else { Console.WriteLine(" {0}","Error bound is infinite"); } } // } } else { Console.WriteLine(""); Console.WriteLine(" {0}","n < 1."); } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }