/****************************************************** * Program to demonstrate the use of multi-dimensional * * Steepest Descent Optimization subroutine * * --------------------------------------------------- * * Reference: BASIC Scientific Subroutines, Vol. II * * By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1]. * * * * C++ version by J-P Moreau, Paris. * * (www.jpmoreau.fr) * * --------------------------------------------------- * * Example: Find a local maximum of * * F(x,y,z) = sin(x)+2*cos(y)-sin(z) * * * * SAMPLE RUN: * * * * How many dimensions: 3 * * * * Convergence criterion: .000000001 * * * * Maximum number of iterations: 50 * * * * Starting constant: 1 * * * * Input the starting point: * * * * X[1] = 1 * * X[2] = 1 * * X[3] = 1 * * * * The results are: * * * * X(1) = 1.5707973 * * X(2) = -0.0000170 * * X(3) = -4.7123856 * * * * Local maximum = 4.0000000 * * * * The number of steps was: 33 * * * ******************************************************/ #include #include #define MACHEPS 1e-15 double D[4], Y[4]; double X[11],X1[11]; double dd,e,xk; int i,l,m,n; /******************************************* Function subroutine */ double Eval() { return sin(X[1])+2.0*cos(X[2])-sin(X[3]); } /*******************************************/ // Functions called by Steepda() void Utilit1() { int i; // Find the magnitude of the gradient dd=0.0; for (i=1; i0.0) xk=xk*1.2; // Decelerate if heading the wrong way e51: if (Y[3]Y[2]) goto e100; // Restore the X[i] for (i=1; i=m) return; if (fabs(Y[3]-Y[2])