列文-伯格马夸尔特算法继承了梯度法和牛顿法的优点,通过调整参数可以在两种算法中切换,该算法在求解函数最小值问题上具有优良特性,尤其是在求解最小问题中的多未知参数;
直接附上matlab代码:
% Set initial guess
x0 = [0; 0; 0];
% Define options for lsqnonlin
options = optimoptions('lsqnonlin','Algorithm','levenberg-marquardt','MaxIterations',1000);
% Call lsqnonlin to minimize the function
[x_min,~,~,~,~] = lsqnonlin(@rosenbrock,x0,[],[],options);
% Calculate the minimum value of the function
y_min = rosenbrock(x_min);
% Print the minimum value and corresponding point
fprintf('Minimum value: %f\n', y_min);
fprintf('Minimum point: (%f, %f, %f)\n', x_min(1), x_min(2), x_min(3));
function y = rosenbrock(x)
% Rosenbrock function
y = x(2)^2 +x(1)^2 + x(3)^2;
end
结果: