% cg.m
function [x, output] = cg(fun, dfun, x0)
% fun: character variable, the name of function computing objective function
% dfun: character variable, the name of function computing the gradient of objective function
% x0: real vector, input initial point
% x :real vector, output solution
% output: structure variable, output the value of f, the number ofiteration, the number of function evaluations and the norm of gradient at last point x
%
% Step 1: initialization
%
epsi = 1.0e-3; % termination tolenrence
k = 0; % the number of iteration
funcN = 0; % the number of function evaluation
rho = 0.01; l = 0.15; u = 0.85;
x = x0;
f = feval(fun, x);
funcN = funcN + 1;
n = length(x0);
%
% Step 2: check convergence condition
%
g = feval(dfun, x);
while norm(g) > epsi & k <= 150
%
% Step 3: form search direction
%
iterm = k - floor(k/(n+1))*(n+1);

这是一个使用Matlab实现的FR共轭梯度法求解优化问题的程序。程序包括了初始化、搜索方向形成、线性搜索、新点计算等步骤,并在示例函数f1上进行了测试,展示了如何调用该方法进行优化求解。
最低0.47元/天 解锁文章
4342

被折叠的 条评论
为什么被折叠?



