On Jul 23, 2:28 pm, Vinzent Steinberg
<
vinzent.steinb...@googlemail.com> wrote:
> On Jul 19, 10:44 pm, Vincent <
vin....@gmx.net> wrote:
>
> > I would like to find a root of a function f.
> > This function computes its result as a sympy.Matrix, and then takes a
> > slice of it and compare it with a numpy.array, which yields a (1
> > dimensional) array of sympy.core.numbers.Real .
>
> > But as it is not an mpmath.matrix (nor a tuple nor a list), findroot()
> > fails to recognize it a multidimensional. I worked around it by
> > "tuplifying" the result. Wouldn't there be a more "foolproof" way,
> > such as testing for the result to be iterable ?
Internally mpmath.matrix tries to call .tolist() (actually that what
you call "tuplifying"), so it should be able to convert numpy and
sympy matrices. mpmathify() is possibly not clever about this, and it
fails anyway on the scalar part.
>
> Currently findroot only expects mpmath types, use nsolve() in sympy if
> you are using sympy types.
>
>
>
> > Symmetrically, findroot only accepts functions having explicitely
> > several variables. Wouldn't there be a simple way to accept also
> > vector functions ?
>
> It also accepts vector functions, if the docstring is not clear about
> this, it's a bug.
>
>
>
> > But now I have strange errors I still have to figure out. Can there be
> > a problem with mpmath failing to convert sympy.core.numbers.Real to
> > mpmath.mpf ?
>
> Feel free to creat an issue for this. :-)
I did so, see
http://code.google.com/p/mpmath/issues/detail?id=154. A
workaround for integers and floats is to convert them to strings. (In
this case, convert the sympy matrix to a list, then convert all sympy
numbers in the nested lists to strings.)
>
> > I put a traceback here in the hope someone recognizes a known problem,
> > but don't loose your time on it. I will further investigate when I
> > have the time to.
>
> > In [60]: findroot(f1,(0.99,2.2),multidimensional=True)
>
> This keyword does not exist.
Actually it does, sorry, I should know my own code better. However, it
should not be necessary to specify it (you can use it to force a
multidimensional solver for the onedimensional case). The problem is
the communication between sympy and mpmath, like you said, and this is
what the traceback is indicating.
Vinzent