# Matlab function "pcg" with zero iterations?

조회 수: 5(최근 30일)
San Carlo 2021년 1월 30일
답변: Shashank Gupta 2021년 2월 2일
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:
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.

댓글을 달려면 로그인하십시오.

### 답변(1개)

Shashank Gupta 2021년 2월 2일
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.

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by