lua-users home
lua-l archive

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

In message <>
          Hur Butun <> wrote:

> I don't really understand what could be the different meanings of solve in
> this case. As I mentioned in my previous message, I would like to obtain
> the value of the friction factor using Colebrook equation.

Sorry - I meant "solve for which variable?". If that is "k" then
what you need is

local x = math.sqrt(lambda)

On the other hand if you want lambda in terms of R, the Reynold's number, k and
d (hydraulic diameter) then you need

lambda = 1/(math.sqrt (fixpoint (f)))


f = function (x)
  local a = ((2.51/R)*x + k/(3.72*d))
  return -2*math.log(a)

where fixpoint(f) solves f(x) == x. To do this you need an initial guess, say 1,
a choice of accuracy epsilon, say 10^(-7) and the Newton-Raphson method:

local df = function (x) -- derivative of f
           local c = -2*(2.51)/R
           local y = (2.51*x)/R + k/(3.72*d))
           return c/y

fixpoint = function (f)
           local g = guess
           while math.abs(g-f(g)) < epsilon do
              g = g - f(g)/df(g)
           return g

This is totally off the cuff, so E&OE.
Gavin Wraith (
Home page: