using System; using System.Text; using System.Runtime.InteropServices; using NagLibrary; class NagE04Functions { static void Main(string[] args) { nag_declarations.e04nfc_qphess_DELEGATE QPHESS = new nag_declarations.e04nfc_qphess_DELEGATE(qphess); nag_declarations.Nag_E04_Opt options = new nag_declarations.Nag_E04_Opt(); nag_declarations.Nag_Comm user_comm = new nag_declarations.Nag_Comm(); nag_declarations.NagError fail = new nag_declarations.NagError(); fail.message = new byte[512]; Encoding enc = Encoding.ASCII; int n = 3; int nclin = 2; int tda = n; double[] a = new double[nclin * tda]; double[] bl = { 0.0, 0.0, 0.0, 9.3145, 1.0 }; double[] bu = { 0.5, 0.5, 0.5, 9.3145, 1.0 }; double[] cvec = { 0.0, 0.0, 0.0 }; double[] h = new double[n * n]; int tdh = n; double[] x = { .33333, .33333, .33333 }; double objf = 0; a[0] = 9.144; a[1] = 9.485; a[2] = 10.567; a[3] = 1; a[4] = 1; a[5] = 1; h[0] = 260.0; h[1] = 90.0; h[2] = 124.0; h[3] = 90; h[4] = 221; h[5] = 15; h[6] = 123; h[7] = 115; h[8] = 221; /* nag_opt_init (e04xxc). * Initialization function for option setting */ nag_declarations.e04xxc(ref options); options.prob = nag_declarations.Nag_ProblemType.Nag_FP; /* nag_opt_qp (e04nfc). * Solve the problem from a cold start. */ nag_declarations.e04nfc(n, nclin, a, tda, bl, bu, cvec, h, tdh, QPHESS, x, ref objf, ref options, ref user_comm, ref fail); if (fail.code != 0) { Console.WriteLine("Error from nag_opt_qp (e04nfc):"); Console.WriteLine(enc.GetString(fail.message)); } } static void qphess(int n, int jthcol, IntPtr h_ptr, int tdh, IntPtr x_ptr, IntPtr hx_ptr, ref nag_declarations.Nag_Comm comm) { nag_declarations.NagError fail = new nag_declarations.NagError(); fail.message = new byte[512]; Encoding enc = Encoding.ASCII; double[] h = new double[n * n]; double[] x = new double[n]; double[] hx = new double[n]; Marshal.Copy(h_ptr, h, 0, n * n); Marshal.Copy(x_ptr, x, 0, n); /* nag_dgemv (f16pac). * Matrix-vector multiply. */ nag_declarations.f16pac(nag_declarations.Nag_OrderType.Nag_RowMajor, nag_declarations.Nag_TransType.Nag_NoTrans, n, n, 1.0, h, tdh, x, 1, 0.0, hx, 1, ref fail); if (fail.code != 0) { Console.WriteLine("Error from nag_dgemv (f16pac):"); Console.WriteLine(enc.GetString(fail.message)); comm.flag = -1; } Marshal.Copy(hx, 0, hx_ptr, n); } }