필터 지우기
필터 지우기

Fixed point (matematice)

조회 수: 2 (최근 30일)
Cillian
Cillian 2012년 5월 7일
Hello.
I have attempt to code a fixed point in MATLAB. But I don't know if this correct, but I think it works.
function sol=fixpunkt(g,x0,tol)
xnew=x0;
xold=x0+2*tol;
while norm(xold-xnew)>tol
xnew = xnew
xnew=g(x0) ;
end
sol=xnew;
When I tried fixpunkt(1,1,5) in the command window, MATLAB works 'busy' for a long long time, I guess it is the while loop doing that,
I would be happy if someone can give a opinion about this.
Regards Cillian

채택된 답변

Richard Brown
Richard Brown 2012년 5월 7일
xold never gets updated, so xnew gets set to the same value every iteration, and the loop never ends ...

추가 답변 (1개)

Titus Edelhofer
Titus Edelhofer 2012년 5월 7일
Hi,
and in addition to Richards observation: it's always not a bad idea to do something like
iter = 0;
maxIter = 50;
while norm(xold-xnew)>tol && iter<maxIter
% do fix point iteration here,
% then:
iter = iter + 1;
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by