[SciPy-Dev] Comments on optimize.newton function

josef.pktd at gmail.com josef.pktd at gmail.com
Sun May 22 13:12:44 EDT 2011


On Sun, May 22, 2011 at 12:59 PM, Gökhan Sever <gokhansever at gmail.com> wrote:
> 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()

I proposed taking logs of left hand side and right hand side
separately, since you are just looking for a zero,
with myfunc.log(),  it is not simplified

(I don't have a quick way to do the symbolic derivative, but there
shouldn'd be any exp left in the expression)

Josef

> 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
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>



More information about the SciPy-Dev mailing list