2 %> Algorithm 9.2: Conjugate gradient algorithm
for quadratic problems. Implementation of algorithm 9.2 of \cite Bier15-book
4 %> @author <a href=
"http://people.epfl.ch/michel.bierlaire">Michel Bierlaire</a>
5 %> @date Sat Apr 5 23:32:26 2014
9 %> @note Tested with \ref run0908cg.m
12 %> Applies the conjugate gradient method to solve \f[\min_x \frac{1}{2} x^T Q x + b^T x\f] where \f$Q \in \mathbb{R}^n\times\mathbb{R}^n \f$ and \f$b \in \mathbb{R}^n\f$.
13 %> @param Q matrix of size \f$n \times n \f$.
14 %> @param b vector of size \f$n\f$.
15 %> @param x0 starting point
16 %> @param printlevel
if different from 0, informations are printed at each iteration (Default: 0)
17 %> @
return [D, solution]
18 %> @
return D: matrix gathering all directions generated by the algorithms
19 %> @
return solution: optimal solution
32 printf("%3d\t%+10.5e\t%+10.5e\t%+10.5e",k,xprint(1),gprint(1),dprint(1)) ;
34 denom = dk' * Q * dk ;
36 error("The matrix must de positive definite") ;
38 alphak = - (dk' * gk) / denom;
39 xk = xk + alphak * dk ;
43 printf("\t%+10.5e\n",alphak) ;
45 printf("\t%+10.5e\t%+10.5e\n",alphak,betak) ;
48 printf("\t%+10.5e\t%+10.5e\t%+10.5e\t\t\n",xprint(i),gprint(i),dprint(i)) ;
51 betak = (gkp1' * gkp1) / (gk' * gk) ;
52 dk = -gkp1 + betak * dk ;
55 % printf("%d %f\n",k,norm(gk)) ;
58 printf("%3d\t%+10.5e\t%+10.5e\t\t\t\n",n+1,xk(i),gk(i)) ;
60 printf("\t%+10.5e\t%+10.5e\t\t\t\n",xk(i),gk(i)) ;
function newtonLocalQuadratic(in obj, in x0, in eps, in cg, in maxiter)
Applies local Newton algorithm to solve where is the gradient of the objective function.
function conjugateGradient(in Q, in b, in x0, in printlevel)
Applies the conjugate gradient method to solve where and .