Hello everybody! In a code I need to solve a linear system with the pcg function already implemented in Matlab. I also need to know how many iterations the pcg function needs to find the solution of the algorithm, so i wrote:
[pk, ~, ~, iters_newton] = pcg(@(p)Hessf_pk(xk, p), -gradf(xk), tollgrad, 50);
iters_newton(k+1) = iters_newton;
Because if I check in the help for pcg it tells me that the fourth output of the pcg function is the number of iterations.
I call this function while solving a minimization problem using Newton Method, and at each iteration (let's call it "outer operations") I call this function, so in the end I have a given number of iterations of the pcg function for each iteration of the Newton Method), and in the end the vector iters_newton gives me the number of iterations for each step of the Newton Method. But while checking this vector, I find out that only the first and the last iteration of the Newton Method are associated with non-zero iterations of the pcg function. In the others, it tells me that the functions has done zero iterations, and I cannot understand if it possible that it actually does zero operations. The help for pcg tells me that this output ranges from 0 to maxiter, so 0 is a value that can be returned, but I wonder if it has some mathematical explanation or not. I really don't understand what happens in this case.