Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: fzero f(x) vs. fminbnd f(x)^2
Replies: 2   Last Post: Apr 25, 2013 6:02 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Jeff Freeman

Posts: 7
Registered: 2/29/12
Re: fzero f(x) vs. fminbnd f(x)^2
Posted: Apr 25, 2013 6:02 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.