// f07ap Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class F07APE { static string datafile = "ExampleData/f07ape.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; double rgf; int i, info, j, n, nrhs; string equed=""; string[] clabs = new string[1]; string[] rlabs = new string[1]; Console.WriteLine("f07ap Example Program Results"); Console.WriteLine(""); // Skip heading in data file 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[] c = new double[n]; double[] ferr = new double[nrhs]; double[] r = new double[n]; int[] ipiv = new int[n]; if (n > 0 ) { // // Read A and B from data file // 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 <= nrhs ; j++) { b[i - 1 , j - 1] = Complex.Parse(sr.Next()); } } // // Solve the equations ax = b for x // F07.f07ap("Equilibrate", "No transpose", n, nrhs, a, af, ipiv, ref equed, r, c, b, x, out rcond, ferr, berr, out rgf, out info); if (info < 0) { return; } // if (info == 0 || info == n + 1) { // // Print solution, error bounds, condition number, the form // of equilibration and the pivot growth factor // 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(""); if (equed == "N") { Console.WriteLine(" {0}","A has not been equilibrated"); } else if (equed == "R") { Console.WriteLine(" {0}","A has been row scaled as diag(R)*A"); } else if (equed == "C") { Console.WriteLine(" {0}","A has been column scaled as A*diag(C)"); } else if (equed == "B") { Console.WriteLine(" {0}","A has been row and column scaled as diag(R)*A*diag(C)"); } Console.WriteLine(""); Console.WriteLine(" {0}","Reciprocal condition number estimate of scaled matrix"); Console.WriteLine(" {0,11:e1}",rcond); Console.WriteLine(""); Console.WriteLine(" {0}","Estimate of reciprocal pivot growth factor"); Console.WriteLine(" {0,11:e1}", rgf); // 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}{3,3}{4}{5}","The (",info,",",info,")"," element of the factor U is zero"); } } else { Console.WriteLine(" {0}","n <= 0"); } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }