Modifying the Tolerance (TolX) inside the Matlab function file (fzero.m).
조회 수: 16 (최근 30일)
이전 댓글 표시
I wrote the code as:
f = @(x) sin(x);
a = -0.01;
b = 0.05;
x = [a b];
options = optimset;
optnew = optimset(options,'TolX',1e-12);
[b,fval,exitflag,output]=fzero(f,x,options);
But, the program keeps using the default TolX !! How can I modify the default Tolerance (TolX) to 1e-12 or to any other value?
댓글 수: 2
Matt J
2018년 7월 19일
But, the program keeps using the default TolX !!
What evidence of that do you see?
답변 (3개)
Aquatris
2018년 7월 19일
편집: Aquatris
2018년 7월 19일
Feed "optnew" to the fzero function, not "options". You are not changing the setting of options with that command.
댓글 수: 3
Aquatris
2018년 7월 19일
For this particular function, it does not affect the results a lot. However, for other functions, it might. For instance, if TolX is increased to 1e-2 for this function, the result is significantly different. I think the OP wanted to make sure he/she/they are able to change the parameter as wanted.
f = @(x) sin(x);
a = -0.01;
b = 0.05;
x = [a b];
options = optimset;
optnew = optimset(options,'TolX',1e-12);
[b,fval,exitflag,output]=fzero(f,x,optnew);b
b =
1.0293e-22
optnew = optimset(options,'TolX',1e-2);
[b,fval,exitflag,output]=fzero(f,x,optnew);b
b =
0.0100
Matt J
2018년 7월 20일
편집: Matt J
2018년 7월 20일
I think the OP wanted to make sure he/she/they are able to change the parameter as wanted.
That is clearly what the OP wanted. My point though, was that the OP would have had the same worry even if the original code had been correct, because comparing the results from different TolX is a misleading test.
For this particular function, it does not affect the results a lot.
It doesn't affect it at all. The results are identical:
optnew = optimset(options,'TolX',1e-12);
b0=fzero(f,x);
b1=fzero(f,x,optnew);
isequal(b0,b1)
ans =
logical
1
Steven Lord
2018년 7월 19일
The relevant section of your code is:
options = optimset;
optnew = optimset(options,'TolX',1e-12);
[b,fval,exitflag,output]=fzero(f,x,options);
You're passing in the original options structure as the third input to fzero, not the modified copy of that original options structure created by the second line of that code segment.
Change the last line to the following and see if it respects the tolerance:
[b,fval,exitflag,output]=fzero(f,x,optnew);
댓글 수: 0
Matt J
2018년 7월 19일
편집: Matt J
2018년 7월 19일
Apart from what Steve and Aquatris mentioned, there is no guarantee that changing TolX will change the results (in fact, I get no change in the result when I fix the code in your example). It is only one of the stopping criteria that can cause the search to terminate.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Behavior and Psychophysics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!