LMFnlsq050.jpg (81.79 KB, 下载次数: 35)
2008-12-13 10:06 上传
源代码参见:http://www.mathworks.com/matlabcentral/fileexchange/16063
Efficient and stable MATLAB version of Fletcher's modification of Levenberg-Marquardt method
The function finds a solution of an algebraic nonlinear problem in the
least squares sense. The standard Levenberg- Marquardt algorithm was modified by Fletcher and coded in FORTRAN many years ago. LMFnlsq is its MATLAB version complemented by setting parameters of Options.
The function calling has one of the following forms:
Options = LMFnlsq; % Settings of Options
Options = LMFnlsq('default');
Options = LMFnlsq(Name1,Value1,Name2,Value2,…);
Options = LMFnlsq(Options,Name1,Value1,Name2,Value2,…);
x = LMFnlsq(Eqns,x0); % Problem solutions
x = LMFnlsq(Eqns,x0,Options);
x = LMFnlsq(Eqns,x0,Name1,Value1,Name2,Value2,…);
[x,ssq] = LMFnlsq(Eqns,x0,…);
[x,ssq,cnt] = LMFnlsq(Eqns,x0,…);
[x,ssq,cnt,nfJ,xy] = LMFnlsq(Eqns,x0,…);
The input variables have the following meaning:
-Eqns is a function name or a handle defining a set of equations to be solved and their residuals,
-x0 is a vector of initial estimates of unknowns,
-Name, Value is a pair of the Options structure. If no Options is defined, default structure items are used. The structure has the following field
names and default values (in braces):
-'Display' for control of iteration results output, {0},
-'Printf' for a handle or function name for output of iteration results,
{printit} subfunction,
-'Jacobian' for a handle of function, which evaluates Jacobian matrix J,
-{finjac} subfunction. If no handle is declared, internal subfunction for finite difference approximation of the matrix J is used.
-'MaxIter' for setting maximum number of iterations, {100},
-'ScaleD' for defining diagonal matrix of scales, {[]},
-'FunTol' for tolerance of final function values, {1e-7},
-'XTol' for tolerance of final solution increments, {1e-7},
-'Lambda' for setting lambda parameter in the first iteration, {0},
-'Trace' for control of storing intermediate results of the vector x , {0};
The output variables are:
-x is the final solution,
-ssq is the sum of squares of residuals of Eqns,
-cnt is a number of iterations needed for finding x,
-nfJ is the number of calling Eqns and 'Jacobian',
-xy is a matrix of intermediate solutions x in iterations.
Example:
The general Rosenbrock's function has the form of a sum of squares:
f(x) = 100(x(2)-x(1)^2)^2 + (1-x(1))^2
Optimum solution gives f(x)=0 for x(1)=x(2)=1. Function f(x) can be
expressed in the form f(x) = f1(x)^2 +f2(x)^2,
where f1(x) = 10(x(2)-x(1)^2) and f2(x) = 1-x(1).
Values of the functions f1(x) and f2(x) can be used as residuals.
LMFnlsq finds the solution of this problem in 17 iterations with default
settings. The function FUN has the form of named function
function r = rosen(x)
% Rosenbrock valey residuals:
r = [ 10*(x(2)-x(1)^2) % first part, f1(x)
1-x(1) % second part, f2(x)
];
or an anonymous function
rosen = @(x) [10*(x(2)-x(1)^2); 1-x(1)];
The solution is x = [1; 1] with ssq = 0.
Anonymous functions are applicable with MATLAB 7.
The function LMFnlsq is able to solve even constrained problems, provided an appropriate penalty function is defined as additional function (see the screenshot and LMFtest.pdf).
The function LMFnlsq overcomes earlier presented function LMFsolve (FEX Id: 16063) in much higher stability.
See LMFtest for a short explanation and solved examples.
2008-12-13 10:06 上传
点击文件名下载附件
下载积分: 贝壳 -1
283.58 KB, 下载次数: 4131, 下载积分: 贝壳 -1