Matlab function "pcg" with zero iterations?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Shashank Gupta
el 2 de Feb. de 2021
Hi Carlo,
Yes, pcg function can return 0 iteration and yes it has some significance. It just mean that the initial guess is a good enough guess. the optimization need not have to proceed any further. The first guess hit the jackpot. Now how do we decide that the first guess is good enough? So we have a tolerance of the solution. If the requirement meets at the first initial guess, the algorithm need not have to compute anything much further.
I hope my understanding of the function helps you.
Cheers.
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!