/* nag_opt_lin_lsq (e04ncc) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * * Mark 6 revised, 2000. * */ #include #include #include #include static void ex1(void); static void ex2(void); int main(void) { Vprintf("e04ncc Example Program Results.\n"); ex1(); ex2(); return EXIT_SUCCESS; } static void ex1(void) { #define MMAX 10 #define NMAX 10 #define NCLIN 10 #define MAXBND NMAX+NCLIN /* Local variables */ double a[NCLIN][NMAX], b[MMAX], bl[MAXBND], bu[MAXBND]; double h[MMAX][NMAX], x[NMAX]; double objf = 0.0; Integer kx[NMAX]; Integer i, j; Integer m, n, nclin; Integer tda, tdh; static NagError fail; fail.print = TRUE; Vprintf("\nExample 1: default options\n"); Vscanf(" %*[^\n]"); /* Skip heading in data file */ Vscanf(" %*[^\n]"); /* Read problem dimensions */ Vscanf(" %*[^\n]"); Vscanf("%ld%ld%ld%*[^\n]", &m, &n, &nclin); if (m <= MMAX && n <= NMAX && nclin <= NCLIN) { tda = NMAX; tdh = NMAX; /* Read h, b, a, bl, bu and x from data file */ Vscanf(" %*[^\n]"); for (i = 0; i < m; ++i) for (j = 0; j < n; ++j) Vscanf("%lf",&h[i][j]); Vscanf(" %*[^\n]"); for (i = 0; i < m; ++i) Vscanf("%lf",&b[i]); if (nclin > 0) { Vscanf(" %*[^\n]"); for (i = 0; i < nclin; ++i) for (j = 0; j < n; ++j) Vscanf("%lf",&a[i][j]); } /* Read lower bounds */ Vscanf(" %*[^\n]"); for (i = 0; i < n + nclin; ++i) Vscanf("%lf",&bl[i]); /* Read upper bounds */ Vscanf(" %*[^\n]"); for (i = 0; i < n + nclin; ++i) Vscanf("%lf",&bu[i]); /* Read the initial point x */ Vscanf(" %*[^\n]"); for (i = 0; i < n; ++i) Vscanf("%lf",&x[i]); e04ncc(m, n, nclin, &a[0][0], tda, bl, bu, (double*)0, b, &h[0][0], tdh, kx, x, &objf, E04_DEFAULT, NAGCOMM_NULL, &fail); } } /* ex1 */ static void ex2(void) { #define MMAX 10 #define NMAX 10 #define NCLIN 10 #define MAXBND NMAX+NCLIN /* Local variables */ double a[NCLIN][NMAX], bl[MAXBND], bu[MAXBND]; double cvec[NMAX], h[MMAX][NMAX], x[NMAX]; double objf; Integer kx[NMAX]; Integer i, j; Integer m, n, nclin; Integer tda, tdh; Nag_E04_Opt options; static NagError fail1, fail2; fail1.print = TRUE; fail2.print = TRUE; Vprintf("\nExample 2: some options are set\n"); Vscanf(" %*[^\n]"); /* Skip heading in data file */ /* Read problem dimensions */ Vscanf(" %*[^\n]"); Vscanf("%ld%ld%ld%*[^\n]", &m, &n, &nclin); if (m <= MMAX && n <= NMAX && nclin <= NCLIN) { tda = NMAX; tdh = NMAX; /* We solve a QP2 type problem in this example */ /* Read cvec, h, a, bl, bu and x from data file */ Vscanf(" %*[^\n]"); for (i = 0; i < m; ++i) Vscanf("%lf",&cvec[i]); Vscanf(" %*[^\n]"); for (i = 0; i < m; ++i) for (j = 0; j < n; ++j) Vscanf("%lf",&h[i][j]); if (nclin > 0) { Vscanf(" %*[^\n]"); for (i = 0; i < nclin; ++i) for (j = 0; j < n; ++j) Vscanf("%lf",&a[i][j]); } /* Read lower bounds */ Vscanf(" %*[^\n]"); for (i = 0; i < n + nclin; ++i) Vscanf("%lf",&bl[i]); /* Read upper bounds */ Vscanf(" %*[^\n]"); for (i = 0; i < n + nclin; ++i) Vscanf("%lf",&bu[i]); /* Read the initial point x */ Vscanf(" %*[^\n]"); for (i = 0; i < n; ++i) Vscanf("%lf",&x[i]); /* Change the problem type */ e04xxc(&options); options.prob = Nag_QP2; e04ncc(m, n, nclin, &a[0][0], tda, bl, bu, cvec, (double*)0, &h[0][0], tdh, kx, x, &objf, &options, NAGCOMM_NULL, &fail1); /* Free options memory */ e04xzc(&options, "all", &fail2); } } /* ex2 */