// f08an Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class F08ANE { static string datafile = "ExampleData/f08ane.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 rnorm=0.0; int i, info, j, m, n; // Skip heading in data file sr.Reset(); sr.Reset(); m = int.Parse(sr.Next()); n = int.Parse(sr.Next()); int nrhs = 1; Complex[,] a = new Complex[m, n]; Complex[,] b = new Complex[Math.Max(m,n),nrhs]; Console.WriteLine("f08an Example Program Results"); Console.WriteLine(""); if (m >0 && n > 0 && m >= n) { // // Read A and B from data file // sr.Reset(); for (i = 1 ; i <= m ; i++) { for (j = 1 ; j <= n ; j++) { a[i - 1 , j - 1] = Complex.Parse(sr.Next()); } } sr.Reset(); for (i = 1 ; i <= m ; i++) { b[i - 1,0] = Complex.Parse(sr.Next()); } // // Solve the least squares problem min( norm2(b - Ax) ) for x // F08.f08an("No transpose", m, n, nrhs, a, b, out info); if (info < 0) { return; } // // Print solution // Console.WriteLine(" {0}", "Least squares solution"); for (i = 1; i <= n; i++) { Console.Write(" {0, 10:f4}", b[i - 1, 0]); } Console.WriteLine(); // // Compute and print estimate of the square root of the residual // sum of squares // Complex[] ArraySlice_b = new Complex[m - n]; for (i = 0; i < m - n; i++) ArraySlice_b[i] = b[n + i, 0]; int ifail; rnorm = F06.f06jj(m - n, ArraySlice_b, 1, out ifail); Console.WriteLine(""); Console.WriteLine(" {0}", "Square root of the residual sum of squares"); Console.WriteLine(" {0,10:e2}", rnorm); } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }