How to display the number of iteration.

This is a code of bisection method of root finding. I know this is not c++ it is in fact matlab. However i always get a more sophisticated answer from c++ guys than matlab guys so yea... bare with me.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ya=feval(f,a);
yb=feval(f,b);
if ya*yb > 0,return,end
max1=1+round((log(b-a)-log(delta))/log(2));
for k=1:max1
    c=(a+b)/2;
    yc=feval(f,c);
    if yc==0
        a=c;
        b=c;
    elseif yb*yc>0
        b=c;
        yb=yc;
    else
        a=c;
        ya=yc;
    end
    if b-a < delta, break,end
end

c=(a+b)/2;
err=abs(b-a);
yc=feval(f,c);


I want to know how to display the numbers of iteration. ty.
bump
If I understood what you want to do correctly, just keep a variable around that gets incremented during each iteration.

PS: The sophistication (if that's how you say it) of answers is proportional to that of the question.
Topic archived. No new replies allowed.