On Wed, Apr 14, 2010 at 6:18 AM, Josh <[email protected]> wrote:
> OK, I figured out how to get an answer that is reproducible in another
> software (PyIMSL's zeroFunction routine, which uses a combination of
> Brent and Muller's methods)!
>
> In [100]: mpmath.findroot(lambda w: 1e80*exp(w) - 1e-300, (-1000,0),
> solver='bisect')
> Out[100]: -874.982335337737
>
> I am still a poor sympy user though. For example, with
> In [101]: mpmath.findroot(lambda w: 1e80*exp(w) - 1e-300, (-1000,0),
> solver='anderson')
> Out[101]:
> -1000.0
> 1.0e-300 - 1.0e+80*e
> -1000.0 + ---------------------------
> -1000.0
> 1.0e+77 - 1.0e+77*e
>
> How do I get a numerical evaluation of this expression?
In general in sympy, you can use .n().
>
> And, when testing Ridder's method, which is what I want to compare
> apples with apples in Scipy, R etc, I get the dreaded
>
> TypeError: cannot create mpf from...
>
> message, and I have no idea what this means, though I keep managing to
> generate it as I play around.
>
>
> In [102]: mpmath.findroot(lambda w: 1e80*exp(w) - 1e-300, (-1000,0),
> solver='ridder')
> ---------------------------------------------------------------------------
> TypeError Traceback (most recent call
> last)
>
> C:\Jabberwocky\examples\<ipython console> in <module>()
>
> C:\Program Files\EPD_511\Lib\site-packages\sympy\mpmath\mptypes.pyc in
> g(*args, **kwargs)
> 66 return +v
> 67 else:
> ---> 68 return f(*args, **kwargs)
> 69 finally:
> 70 self.mp.prec = orig
>
> C:\Program Files\EPD_511\Lib\site-packages\sympy\mpmath
> \optimization.pyc in findroot(f, x0, solver, tol, verbose, verify,
> force_type, **kwargs)
> 942 maxsteps = iterations.maxsteps
> 943 i = 0
> --> 944 for x, error in iterations:
> 945 if verbose:
> 946 print 'x: ', x
>
> C:\Program Files\EPD_511\Lib\site-packages\sympy\mpmath
> \optimization.pyc in __iter__(self)
> 483 x3 = 0.5*(x1 + x2)
> 484 fx3 = f(x3)
> --> 485 x4 = x3 + (x3 - x1) * sign(fx1 - fx2) * fx3 /
> sqrt(fx3**2 - fx1*fx2)
> 486 fx4 = f(x4)
> 487 if abs(fx4) < self.tol:
>
> C:\Program Files\EPD_511\Lib\site-packages\sympy\mpmath\functions.pyc
> in sign(ctx, x)
> 251
> 252 """
> --> 253 x = ctx.convert(x)
> 254 if not x or ctx.isnan(x):
> 255 return x
>
> C:\Program Files\EPD_511\Lib\site-packages\sympy\mpmath\mptypes.pyc in
> convert(ctx, x, strings)
> 361 if hasattr(x, '_mpmath_'):
> 362 return ctx.convert(x._mpmath_(*prec_rounding))
> --> 363 raise TypeError("cannot create mpf from " + repr(x))
> 364
> 365 def isnan(ctx, x):
>
> TypeError: cannot create mpf from -1.0e+80 + 1.0e+80*exp(-1000.0)
This has been fixed in the latest sympy (use the sympy git), but I get
some ugly expression. If I evaluate it, I get:
In [3]: mpmath.findroot(lambda w: 1e80*exp(w) - 1e-300, (-1000,0),
olver='ridder').n()
Out[3]: -1000.00000000000
Is this correct?
Ondrej
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.