// e04fy Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class E04FYE { static int m = 15; static int nt = 3; static double[] ruser = new double[m + m * nt]; static int[] iuser = new int[1]; static string datafile = "ExampleData/e04fye.d"; // as a command line argument. It defaults to the named file specified below otherwise. // static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { E04.E04FY_LSFUN1 lsfun1E04FY = new E04.E04FY_LSFUN1(lsfun1); try { DataReader sr = new DataReader(datafile); double fsumsq = 0.0; int i, ifail, j, k; int n = 3; double[,] t = new double[m, nt]; double[] x = new double[n]; double[] y = new double[m]; Console.WriteLine("e04fy Example Program Results"); // Skip heading in data file sr.Reset(); // // Observations of tj (j = 1, 2, 3) are held in t[i-1, j-1] // (i = 1, 2, . . . , 15) // iuser[0] = nt; k = m; for (i = 1; i <= m; i++) { sr.Reset(); y[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); for (j = 1; j <= nt; j++) { t[i - 1, j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } ruser[i - 1] = y[i - 1]; for (j = 1; j <= nt; j++) { ruser[k + j - 1] = t[i - 1, j - 1]; } k = k + nt; } // x[0] = 0.50e0; x[1] = 1.00e0; x[2] = 1.50e0; // E04.e04fy(m, n, lsfun1E04FY, x, out fsumsq, out ifail); // if (ifail < 0) { Console.WriteLine(""); Console.WriteLine(" ** e04fy returned with ifail = {0, 3}", ifail); } else { if (ifail != 0) { Console.WriteLine(""); Console.WriteLine(" {0}{1,3}{2}", "Error exit type", ifail, " - see method document"); } // if (ifail != 1) { Console.WriteLine(""); Console.WriteLine(" {0}{1,12:f4}", "On exit, the sum of squares is", fsumsq); Console.Write(" {0}", "at the point"); for (j = 1; j <= n; j++) { Console.Write(" {0, 12:f4}", x[j - 1]); } Console.WriteLine(); } } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } // public static void lsfun1(int m, int n, double[] xc, double[] fvec) { int i, k; k = m; for (i = 1; i <= m; i++) { fvec[i - 1] = xc[0] + ruser[k + 1 - 1] / (xc[1] * ruser[k + 2 - 1] + xc[2] * ruser[k + 3 - 1]) - ruser[i - 1]; k = k + iuser[0]; } } } }