// f07fp Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class F07FPE { static string datafile = "ExampleData/f07fpe.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 rcond=0.0; int i, info, j, n, nrhs; string equed=""; sr.Reset(); sr.Reset(); n = int.Parse(sr.Next()); nrhs = int.Parse(sr.Next()); Complex[,] a = new Complex[n, n]; Complex[,] af = new Complex[n, n]; Complex[,] b = new Complex[n, nrhs]; Complex[,] x = new Complex[n, nrhs]; double[] berr = new double[nrhs]; double[] ferr = new double[nrhs]; double[] s = new double[n]; string[] clabs = new string[1]; string[] rlabs = new string[1]; Console.WriteLine("f07fp Example Program Results"); Console.WriteLine(""); // Skip heading in data file if (n > 0 ) { // // Read the upper triangular part of A from data file // sr.Reset(); for (i = 1 ; i <= n ; i++) { for (j = i ; j <= n ; j++) { a[i - 1 , j - 1] = Complex.Parse(sr.Next()); } } // // Read B from data file // sr.Reset(); for (i = 1 ; i <= n ; i++) { for (j = 1 ; j <= nrhs ; j++) { b[i - 1 , j - 1] = Complex.Parse(sr.Next()); } } // // Solve the equations ax = b for x // F07.f07fp("Equilibration", "Upper", n, nrhs, a, af, ref equed, s, b, x, out rcond, ferr, berr, out info); if (info < 0) { return; } // if (((info == 0)) || ((info == n + 1))) { // // Print solution, error bounds, condition number and the form // of equilibration // Console.WriteLine("Solution(s)\n"); for (i = 1 ; i <= n ; i++) { for (j = 1 ; j <= nrhs ; j++) { Console.Write("{0, 20:f4}", x[i-1,j-1]); } Console.WriteLine(""); } Console.WriteLine(""); Console.WriteLine(" {0}","Backward errors (machine-dependent)"); for (j = 1 ; j <= nrhs ; j++) { Console.Write(" {0, 3:e1}", berr[j - 1]); } Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine(" {0}","Estimated forward error bounds (machine-dependent)"); for (j = 1 ; j <= nrhs ; j++) { Console.Write(" {0, 3:e1}", ferr[j - 1]); } Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine(" {0}","Estimate of reciprocal condition number"); Console.WriteLine(" {0,11:e1}",rcond); Console.WriteLine(""); if (equed == "N") { Console.WriteLine(" {0}","A has not been equilibrated"); } else if (equed == "Y") { Console.WriteLine(" {0}","A has been row and column scaled as diag(S)*A*diag(S)"); } // if (info == n + 1) { Console.WriteLine(""); Console.WriteLine(" {0}","The matrix A is singular to working precision"); } } else if (info > 0) { Console.WriteLine(" {0}{1,3}{2}","The leading minor of order ",info," is not positive definite"); } } else { Console.WriteLine(" {0}","n <= 0"); } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }