///////////////////////////////////////////////////////////////////////////////// // // Demonstration driver program for the Levenberg - Marquardt minimization // algorithm // Copyright (C) 2004-05 Manolis Lourakis (lourakis@ics.forth.gr) // Institute of Computer Science, Foundation for Research & Technology - Hellas // Heraklion, Crete, Greece. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // ///////////////////////////////////////////////////////////////////////////////// /******************************************************************************** * Levenberg-Marquardt minimization demo driver. Only the double precision versions * are tested here. See the Meyer case for an example of verifying the jacobian ********************************************************************************/ #include #include #include #include #include "lm.h" /* Sample functions to be minimized with LM and their jacobians. * More test functions at http://www.csit.fsu.edu/~burkardt/f_src/test_nls/test_nls.html * Check also the CUTE problems collection at ftp://ftp.numerical.rl.ac.uk/pub/cute/; * CUTE is searchable through http://numawww.mathematik.tu-darmstadt.de:8081/opti/select.html * CUTE problems can also be solved through the AMPL web interface at http://www.ampl.com/TRYAMPL/startup.html */ #define ROSD 105.0 /* Rosenbrock function, global minimum at (1, 1) */ void ros(double *p, double *x, int m, int n, void *data) { register int i; for(i=0; i=0)? 0.25 : -0.25; x[0]=10.0*(p[2] - 10.0*theta); x[1]=10.0*(sqrt(p[0]*p[0] + p[1]*p[1]) - 1.0); x[2]=p[2]; } void jachelval(double *p, double *jac, int m, int n, void *data) { register int i=0; double tmp; tmp=p[0]*p[0] + p[1]*p[1]; jac[i++]=50.0*p[1]/(M_PI*tmp); jac[i++]=-50.0*p[0]/(M_PI*tmp); jac[i++]=10.0; jac[i++]=10.0*p[0]/sqrt(tmp); jac[i++]=10.0*p[1]/sqrt(tmp); jac[i++]=0.0; jac[i++]=0.0; jac[i++]=0.0; jac[i++]=1.0; } /* Boggs - Tolle problem 3 (linearly constrained), minimum at (-0.76744, 0.25581, 0.62791, -0.11628, 0.25581) * constr1: p[0] + 3*p[1] = 0; * constr2: p[2] + p[3] - 2*p[4] = 0; * constr3: p[1] - p[4] = 0; */ void bt3(double *p, double *x, int m, int n, void *data) { register int i; double t1, t2, t3, t4; t1=p[0]-p[1]; t2=p[1]+p[2]-2.0; t3=p[3]-1.0; t4=p[4]-1.0; for(i=0; i=-1.5; */ void hs01(double *p, double *x, int m, int n, void *data) { double t; t=p[0]*p[0]; x[0]=10.0*(p[1]-t); x[1]=1.0-p[0]; } void jachs01(double *p, double *jac, int m, int n, void *data) { register int j=0; jac[j++]=-20.0*p[0]; jac[j++]=10.0; jac[j++]=-1.0; jac[j++]=0.0; } /* Hock - Schittkowski MODIFIED problem 21 (box constrained), minimum at (2.0, 0.0) * constr1: 2 <= p[0] <=50; * constr2: -50 <= p[1] <=50; * * Original HS21 has the additional contraint 10*p[0] - p[1] >= 10; which is inactive * at the solution, so it is dropped here. */ void hs21(double *p, double *x, int m, int n, void *data) { x[0]=p[0]/10.0; x[1]=p[1]; } void jachs21(double *p, double *jac, int m, int n, void *data) { register int j=0; jac[j++]=0.1; jac[j++]=0.0; jac[j++]=0.0; jac[j++]=1.0; } /* Problem hatfldb (box constrained), minimum at (0.947214, 0.8, 0.64, 0.4096) * constri: p[i]>=0.0; (i=1..4) * constr5: p[1]<=0.8; */ void hatfldb(double *p, double *x, int m, int n, void *data) { register int i; x[0]=p[0]-1.0; for(i=1; i=0.0; (i=1..4) * constri+4: p[i]<=10.0; (i=1..4) */ void hatfldc(double *p, double *x, int m, int n, void *data) { register int i; x[0]=p[0]-1.0; for(i=1; i=0.0001; (i=1..5) * constri+5: p[i]<=100.0; (i=1..5) */ void combust(double *p, double *x, int m, int n, void *data) { double R, R5, R6, R7, R8, R9, R10; R=10; R5=0.193; R6=4.10622*1e-4; R7=5.45177*1e-4; R8=4.4975*1e-7; R9=3.40735*1e-5; R10=9.615*1e-7; x[0]=p[0]*p[1]+p[0]-3*p[4]; x[1]=2*p[0]*p[1]+p[0]+3*R10*p[1]*p[1]+p[1]*p[2]*p[2]+R7*p[1]*p[2]+R9*p[1]*p[3]+R8*p[1]-R*p[4]; x[2]=2*p[1]*p[2]*p[2]+R7*p[1]*p[2]+2*R5*p[2]*p[2]+R6*p[2]-8*p[4]; x[3]=R9*p[1]*p[3]+2*p[3]*p[3]-4*R*p[4]; x[4]=p[0]*p[1]+p[0]+R10*p[1]*p[1]+p[1]*p[2]*p[2]+R7*p[1]*p[2]+R9*p[1]*p[3]+R8*p[1]+R5*p[2]*p[2]+R6*p[2]+p[3]*p[3]-1.0; } void jaccombust(double *p, double *jac, int m, int n, void *data) { register int j=0; double R, R5, R6, R7, R8, R9, R10; R=10; R5=0.193; R6=4.10622*1e-4; R7=5.45177*1e-4; R8=4.4975*1e-7; R9=3.40735*1e-5; R10=9.615*1e-7; for(j=0; j