Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: fzero f(x) vs. fminbnd f(x)^2
Posted:
Apr 25, 2013 6:02 PM


I'm assuming this topic has been put to bed, but I thought I'd add a bit of knowledge gained by my own investigation for the sake of future readers.
I have to solve the following equation for the variable f (For those who recognize, f is the Darcy friction factor from the Moody diagram http://en.wikipedia.org/wiki/Moody_chart):
1/sqrt(f)) = 2.0 * log10(((epsilon/Dh)/3.7) + (2.51/(Re*sqrt(f))))
This equation is monotonically decreasing and generally behaves very well.
I repeat the process hundreds of times inside of multiple calls to ode45, and some testing with Profiler suggests that this is *the* most time consuming part of the entire code.
I tested four different root solving options, and they are listed below from most time (1) to least time (4). All for methods found the same solution. The solver (fzero or fminbnd) was called roughly 1100 times in each case. The total time of each program and the number of calls to the function [variants of @(f) (LHS  RHS)] are also listed below.
(1) f = fzero(@(f) (LHS  RHS), 0.01); Time = 1.444 s Calls = 25986
(3) f = fminbnd(@(f) abs(LHS  RHS), 0.0001, 0.1); Time = 1.402 s Calls = 15319
(2) f = fminbnd(@(f) (LHS  RHS)^2, 0.0001, 0.1); Time = 1.203 s Calls = 14156
(4) f = fzero(@(f) (LHS  RHS), [0.0001, 0.1]); Time = 1.048 s Calls = 13811
It seems that fzero has less overhead iff it is given a bounding interval, and you can't use fminbnd without a bounding interval anyways. I can't particularly talk to the robustness of the two different tools, but for simple root solving I recommend fzero with a bounding interval.
Hope this helps, Jeff Freeman



