comparison scripts/optimization/fsolve.m @ 21099:52af4092f863

For optimization scripts, correctly choose tolerance (eps) based on class of fun and X0. * fminbnd.m, fminsearch.m, fminunc.m, fsolve.m: Use 'isa (..., "single")' to check both initial guess X0 and result of function evaluation to decide whether eps should be single or double.
author Rik <rik@octave.org>
date Mon, 18 Jan 2016 10:00:56 -0800
parents 516bb87ea72e
children 3be6a07e8bad
comparison
equal deleted inserted replaced
21098:99d373870017 21099:52af4092f863
183 if (funvalchk) 183 if (funvalchk)
184 ## Replace fcn with a guarded version. 184 ## Replace fcn with a guarded version.
185 fcn = @(x) guarded_eval (fcn, x, complexeqn); 185 fcn = @(x) guarded_eval (fcn, x, complexeqn);
186 endif 186 endif
187 187
188 ## These defaults are rather stringent. I think that normally, user 188 ## These defaults are rather stringent.
189 ## prefers accuracy to performance. 189 ## Normally user prefers accuracy to performance.
190
191 macheps = eps (class (x0));
192 190
193 tolx = optimget (options, "TolX", 1e-7); 191 tolx = optimget (options, "TolX", 1e-7);
194 tolf = optimget (options, "TolFun", 1e-7); 192 tolf = optimget (options, "TolFun", 1e-7);
195 193
196 factor = 1; 194 factor = 1;
219 stop = outfcn (x, optimvalues, state); 217 stop = outfcn (x, optimvalues, state);
220 if (stop) 218 if (stop)
221 info = -1; 219 info = -1;
222 break; 220 break;
223 endif 221 endif
222 endif
223
224 if (isa (x0, "single") || isa (fvec, "single"))
225 macheps = eps ("single");
226 else
227 macheps = eps ("double");
224 endif 228 endif
225 229
226 nsuciter = 0; 230 nsuciter = 0;
227 231
228 ## Outer loop. 232 ## Outer loop.