"Fossies" - the Fresh Open Source Software Archive

Member "ccmath-2.2.1/roots/test/toptmiz.c" (17 Nov 2000, 1720 Bytes) of package /linux/misc/old/ccmath-2.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*  toptmiz.c    CCMATH mathematics library source code.
    2  *
    3  *  Copyright (C)  2000   Daniel A. Atkinson    All rights reserved.
    4  *  This code may be redistributed under the terms of the GNU library
    5  *  public license (LGPL). ( See the lgpl.license file for details.)
    6  * ------------------------------------------------------------------------
    7  */
    8 /*
    9     Test:  optmiz
   10 
   11     A new function can be specified by setting the system dimension ND
   12     and coding a new 'double func(x)' to evaluate the criteria function,
   13     with x the parameter vector.
   14 */
   15 #include "ccmath.h"
   16 #define ND 2
   17 char nm[]="Rosenbrock";
   18 void main(void)
   19 { double x[ND],de,test;
   20   double func(double *x);
   21   int i,n=ND,max=60;
   22   test=1.e-12; de=1.e-9;
   23   printf("     Test of Optimizer (%s function)\n",nm);
   24   printf(" max iterations = %d\n",max);
   25   printf(" convergence threshold= %8.2e\n",test);
   26   printf(" derivative interval= %8.2e\n",de);
   27   fprintf(stderr," input initial vector (%d components)\n",n);
   28   for(i=0; i<n ;) scanf("%lf",x+i++);
   29   printf(" input vector: ");
   30   for(i=0; i<n ;) printf("  %f",x[i++]); printf("\n");
   31   if(optmiz(x,n,func,de,test,max)) printf(" optimal solution\n");
   32   else printf(" convergence failure\n");
   33   printf(" x-vector: ");
   34   for(i=0; i<n ;) printf("  %f",x[i++]); printf("\n");    
   35   printf(" minimum F(x)= %e\n",func(x));
   36 }
   37 /* Rosenbrock criteria function */
   38 double func(double *x)
   39 { double f,y;
   40   y=x[0]; f=1.-y; y=x[1]-y*y;
   41   return 100.*y*y+f*f;
   42 }
   43 /* Test output
   44 
   45      Test of Optimizer (Rosenbrock function)
   46  max iterations = 60
   47  convergence threshold= 1.00e-12
   48  derivative interval= 1.00e-09
   49  input vector:   -1.000000  1.000000
   50  optimal solution
   51  x-vector:   1.000000  1.000000
   52  minimum F(x)= 6.019086e-17
   53 */