// e04jy Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class E04JYE { static void Main(String[] args) { StartExample(); } public static void StartExample() { E04.E04JY_FUNCT1 funct1E04JY = new E04.E04JY_FUNCT1(funct1); try { double f = 0.0; double phm; int ibound, ifail, j; int n = 4; double[] bl = new double[n]; double[] bu = new double[n]; double[] fdiff = new double[n]; double[] x = new double[n]; int[] bndinfo = new int[n]; int freevar; Console.WriteLine("e04jy Example Program Results"); x[0] = 3.00e0; x[1] = -1.00e0; x[2] = 0.00e0; x[3] = 1.00e0; ibound = 0; bl[0] = 1.00e0; bu[0] = 3.00e0; bl[1] = -2.00e0; bu[1] = 0.00e0; // // x[2] is unconstrained, so we set bl[2] to a large negative // number and bu[2] to a large positive number. // bl[2] = -1.00e6; bu[2] = 1.00e6; bl[3] = 1.00e0; bu[3] = 3.00e0; int nftotl; // E04.e04jy(n, ibound, funct1E04JY, bl, bu, x, out f, out nftotl, bndinfo, out freevar, fdiff, out phm, out ifail); // if (ifail == 0 || ifail == 3 || ifail >= 5 ) { Console.WriteLine(""); Console.WriteLine(" {0}{1,8:f4}", "Function value on exit is ", f); Console.Write(" " + " {0}", "at the point"); for (j = 1; j <= n; j++) { Console.Write(" " + " {0, 9:f4}", x[j - 1]); } Console.WriteLine(" "); } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } // public static void funct1(int n, double[] xc, out double fc) { // Routine to evaluate objective function. double x1, x2, x3, x4; x1 = xc[0]; x2 = xc[1]; x3 = xc[2]; x4 = xc[3]; fc = ((x1 + 10.00e0 * x2)) * ((x1 + 10.00e0 * x2)) + 5.00e0 * ((x3 - x4)) * ((x3 - x4)) + Math.Pow((x2 - 2.00e0 * x3), 4) + 10.00e0 * Math.Pow((x1 - x4), 4); } } }