MATLAB - Fixed point iteration

394 views Asked by At

I'm trying to figure out how to create a function for fixed point iteration. But I have been stuck on this for a good hour now and I am finally caving in.

So what am I doing wrong?

I would suspect that I'm updating wrong, but I am not really sure.

All help would be greatly appriciated!

function fixedpointint(x1,iteration,g,TOL)
x2 = g(x1);
i = 0;
while i<iteration && abs(x1-x2)>TOL 
    x1 = x2;
    x2 = g(x1);
    i = i + 1;
end
end 

I call the function with:

g = @(x)exp(-x)*2;
fixedpointint(0.3,1000,g,0.001)

When I remove the i<iteration test, the function works. I do however not understand why omitting it would make it work?

0

There are 0 answers