Note that there are some explanatory texts on larger screens.

plurals
  1. POsolving colebrook (nonlinear) equation in python
    text
    copied!<p>I want to do in python <a href="https://stackoverflow.com/questions/5688510/solution-of-an-implicit-equation-with-fzero-on-matlab">what this guy did</a> in MATLAB.</p> <p>I have installed anaconda, so i have numpy and sympy libraries. So far I have tried with numpy nsolve, but that doesn't work. I should say I'm new with python, and also that I konw how to do it in MATLAB :P.</p> <p><a href="http://www.wolframalpha.com/input/?i=-2*log%28%282.51/%28331428*sqrt%28x%29%29%29%2b%280.0002/%283.71*0.26%29%29%29=1/sqrt%28x%29" rel="nofollow noreferrer">The equation</a>:</p> <p><code>-2*log(( 2.51/(331428*sqrt(x)) ) + ( 0.0002 /(3.71*0.26)) ) = 1/sqrt(x)</code></p> <p>Normally, I would solve this iteratively, simply guessing x on the left and than solving for the x on the right. Put solution on the left, solve again. Repeat until left x is close to right. I have an idea what solution should be. </p> <p>So I could do that, but that's not very cool. I want to do it numerically. My 15€ Casio calculator can solve it as is, so I think it shouldn't be to complicated?</p> <p>Thank you for your help,</p> <p>edit: so I have tried the following:</p> <pre><code>from scipy.optimize import brentq w=10; d=0.22; rho=1.18; ni=18.2e-6; Re=(w*d*rho)/ni k=0.2e-3; d=0.26; def f(x,Re,k,d): return ( -2*log((2.51/(Re*sqrt(x)))+(k/(3.71*d)),10)*sqrt(x)+1 ); print( scipy.optimize.brentq ( f,0.0,1.0,xtol=4.44e-12,maxiter=100,args=(),full_output=True,disp=True ) ); </code></pre> <p>And i get this result:</p> <pre><code> r = _zeros._brentq(f,a,b,xtol,maxiter,args,full_output,disp) TypeError: f() takes exactly 4 arguments (1 given) </code></pre> <p>Is it because I'm solving also solving for constants?</p> <p>edit2: so I think I have to assign constants via args=() keyword, so I changed:</p> <pre><code>f,0.0,1.0,xtol=4.44e-12,maxiter=100,args=(Re,k,d),full_output=True,disp=True </code></pre> <p>but now I get this:</p> <pre><code>-2*log((2.51/(Re*sqrt(x)))+(k/(3.71*d)),10)*sqrt(x)+1 TypeError: return arrays must be of ArrayType </code></pre> <p>Anyway, when I put in a different equation; lets say <code>2*x*Re+(k*d)/(x+5)</code> it works, so I guess I have to transform the equation.</p> <p>so it dies here: log(x,10).. </p> <p>edit4: correct syntax is log10(x)... Now it works but I get zero as a result</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload