% 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
%