Using an iterative method with scalar functions/function handles (help me fix this code)
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I have a function that accepts and returns a scalar. If I code like this, minres returns an incorrect result, stating that the iteration gave a relative residual of 0:
f = @(x)(x.*x);
b = 10;
res = minres(f, b);
The result changes if I specify an initial guess, otherwise 10 in this case. I was assuming that I'm doing something wrong with function handles, but if b = [10;1;5] for example, the relative residual is evaluated correctly (even though there's no convergence). Any comments, ideas?
I am using version R2011a.
Best regards and thanks in advance
edit: In the meantime, I have found a work-around by shifting the function and using fzero to find the root. fzero isn't mentioned in the doc for any of the iterative solvers or even function handles, sadly, so it took me a few hours to stumble over this command.
I'm leaving the question up because the behavior of the code still seems strange to me.
댓글 수: 0
답변 (1개)
Ivan van der Kroon
2011년 7월 7일
In the doc of fzero 'Find root of continuous function of one variable', which you clearly need here.
Doc of minres 'find a minimum norm residual solution x to the system of linear equations', as your function is not linear it will not work. You can try
f = @(x)(2.*x);
b = 10;
res = minres(f, b)
minres converged at iteration 1 to a solution with relative residual 0.
res =
5
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!