// f07th Example Program Text // Mark 15 Release. NAG Copyright 1991. // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class F07THE { static string datafile = "ExampleData/f07the.d"; const int nin=5; const int nmax=8; const int nrhmax=nmax; const int lda=nmax; const int ldb=nmax; const int ldx=nmax; const string trans="N"; const string diag="N"; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { DataReader sr = new DataReader(datafile); int i=0, info=0, j=0, n=0, nrhs=0; string uplo=""; double[,] a = new double[lda, nmax]; double[,] b = new double[ldb, nrhmax]; double[] berr = new double[8]; double[] ferr = new double[8]; double[] work = new double[24]; double[,] x = new double[ldx, nmax]; int[] iwork = new int[8]; int ifail; Console.WriteLine("f07th Example Program Results"); // Skip heading in data file sr.Reset(); sr.Reset(); n = int.Parse(sr.Next()); nrhs = int.Parse(sr.Next()); if ((n <= nmax) && (nrhs <= nrhmax)) { // // Read A and B from data file, and copy B to X // sr.Reset(); uplo = sr.Next(); if (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 if (uplo == "L") { 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); } } } sr.Reset(); for (i = 1 ; i <= n ; i++) { for (j = 1 ; j <= nrhs ; j++) { b[i - 1 , j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } } // F06.f06qf("General", n, nrhs, b, x,out info); // // Compute solution in the array X // F07.f07te(uplo, trans, diag, n, nrhs, a, x, out info); // // Compute backward errors and estimated bounds on the // forward errors // F07.f07th(uplo, trans, diag, n, nrhs, a, b, x, ferr, berr, out info); // // Print solution // Console.WriteLine(""); X04.x04ca("General", "", n, nrhs, x, "Solution(s)", out ifail); Console.WriteLine(""); Console.WriteLine(" {0}","Backward errors (machine-dependent)"); for (j = 1 ; j <= nrhs ; j++) { // nested do in write Console.WriteLine(" {0}", berr[j - 1]); } Console.WriteLine(""); Console.WriteLine(" {0}","Estimated forward error bounds (machine-dependent)"); for (j = 1 ; j <= nrhs ; j++) { // nested do in write Console.WriteLine(" {0}", ferr[j - 1]); } Console.WriteLine(""); } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }