[SciPy-Dev] Comments on optimize.newton function

Gökhan Sever gokhansever at gmail.com
Sun May 22 12:59:41 EDT 2011


On Sun, May 22, 2011 at 6:22 AM,  <josef.pktd at gmail.com> wrote:
>> cpdef double petters_solve_for_rw(double x, double rd, double rh):
>>    return rh - exp(kelvin/x) * (x**3 - rd**3) / (x**3 - rd**3 * (1.0 - kappa))
>
> Wouldn't this be easier (for derivatives), and maybe be more stable, taking logs
>
> np.log(rh) -  kelvin/x + np.log(..) ...  ?
>
> (independently of any improvement to the solvers)
>

Seems like this produces more terms in derivatives (tested below in
Sage v.4.6.1 via notebook):

myfunc      	
(rd^3 - x^3)*e^(kelvin/x)/((kappa - 1.0)*rd^3 + x^3) + rh

myfunc.derivative(x).simplify()
-3*(rd^3 - x^3)*x^2*e^(kelvin/x)/((kappa - 1.0)*rd^3 + x^3)^2 -
3*x^2*e^(kelvin/x)/((kappa - 1.0)*rd^3 + x^3) - (rd^3 -
x^3)*kelvin*e^(kelvin/x)/(((kappa - 1.0)*rd^3 + x^3)*x^2)

p = myfunc.log()
p.derivative(x).simplify()
-(3*(rd^3 - x^3)*x^2*e^(kelvin/x)/((kappa - 1.0)*rd^3 + x^3)^2 +
3*x^2*e^(kelvin/x)/((kappa - 1.0)*rd^3 + x^3) + (rd^3 -
x^3)*kelvin*e^(kelvin/x)/(((kappa - 1.0)*rd^3 + x^3)*x^2))/((rd^3 -
x^3)*e^(kelvin/x)/((kappa - 1.0)*rd^3 + x^3) + rh)

-- 
Gökhan



More information about the SciPy-Dev mailing list