[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fzero problem

From: jmb
Subject: fzero problem
Date: Tue, 21 Apr 2015 22:06:23 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0


I am getting an error when I try to run moody.m from:

function f = moody(ed,Re,verbose)
% moody  Find friction factor by solving the Colebrook equation (Moody
% Synopsis:  f = moody(ed,Re)
% Input:     ed = relative roughness = epsilon/diameter
%            Re = Reynolds number
% Output:    f = friction factor
% Note:      Laminar and turbulent flow are correctly accounted for
if Re<0
  error(sprintf('Reynolds number = %f cannot be negative',Re));
elseif Re<2000
  f = 64/Re;  return      %  laminar flow
if ed>0.05
  warning(sprintf('epsilon/diameter ratio = %f is not on Moody chart',ed));
if Re<4000, warning('Re = %f in transition range',Re);  end
% --- Use fzero to find f from Colebrook equation.
%     coleFun is an inline function object to evaluate F(f,e/d,Re)
%     fzero returns the value of f such that F(f,e/d/Re) = 0 (approximately)
%     fi = initial guess from Haaland equation, see White, equation 6.64a
%     Iterations of fzero are terminated when f is known to within +/- dfTol
coleFun = inline('1.0/sqrt(f) + 2.0*log10( ed/3.7 + 2.51/( Re*sqrt(f))
fi = 1/(1.8*log10(6.9/Re + (ed/3.7)^1.11))^2;   %  initial guess at f
dfTol = 5e-6;
f = fzero(coleFun,fi,optimset('TolX',dfTol,'Display','off'),ed,Re);
% --- sanity check:
if f<0, error(sprintf('Friction factor = %f, but cannot be
negative',f)); end

When I run it:
The paper says one should get 0.0265, but I get:
        warning: unrecognized option: Display
        error: Invalid call to fzero.  Correct usage is:
        -- Function File: [X, FVAL, INFO, OUTPUT] = fzero (FUN, X0, OPTIONS)

I have tried removing the 'Display':
        f = fzero(coleFun,fi,optimset('TolX',dfTol),ed,Re);
but it still does not work...

Any ideas why fzero is complaining?

I tried a simple version of it
        function f = test_moody(verbose)
        coleFun = inline('x^2+4*x+4','x')
        # coleFun = inline('x^2+a*x+4','x', 'a')
        fi = 0;                % initial guess at x
        dfTol = 5e-6;

#       f = fzero(coleFun,fi,optimset('TolX',dfTol));
        f = fsolve(coleFun,fi,optimset('TolX',dfTol));
and I get:
        coleFun = f(x) = x^2+4*x+4
        error: fzero: not a valid initial bracketing
but fsolve works...

Is this the explanation?

BTW: I am trying it with Octave = 3.2.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]