On Sat, Jan 17, 2009 at 11:09 AM, Andrew Straw <[email protected]> wrote:
>
> Hi, I'm trying to get lambdify to take a vector as input so that I can
> have a function G(x) where x is a vector. (The ultimate aim is to
> evaluate linearizations at certain locations where the linearized
> function is defined as a sympy Matrix.) Attempting to modify
> sympy/test_external/test_numpy.py to include the test case results in
> the traceback below. Should I expect this to work? If so, what am I
> doing wrong?
>
> def test_lambdify_matrix_vec_input():
> x,y,z=sympy.symbols('xyz')
> X=sympy.Matrix([x,y,z]) # our input vector
> M=sympy.Matrix([[X[0]**2, x[0]*X[1], X[0]*X[2]],
^^^ it's because x[0] should be X[0], doesn't it?
Otherwise I usually play with the idea in isympy, e.g.:
In [1]: X = Matrix([x,y,z])
In [2]: M = Matrix([[X[0]**2, x[0]*X[1], X[0]*X[2]],
...: [X[1]*X[0], X[1]**2, X[1]*X[2]],
...: [X[2]*X[0], X[2]*X[1], X[2]**2]])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/ondra/repos/sympy/<ipython console> in <module>()
TypeError: 'Symbol' object is unindexable
Then it reveals the problem immediatelly. However, when you enter it correctly:
In [10]: M
Out[10]:
⎡ 2 ⎤
⎢x x⋅y x⋅z⎥
⎢ ⎥
⎢ 2 ⎥
⎢x⋅y y y⋅z⎥
⎢ ⎥
⎢ 2 ⎥
⎣x⋅z y⋅z z ⎦
In [11]: f = lambdify(X, M, "numpy")
------------------------------------------------------------
File "<string>", line 1
lambda [x]
^
SyntaxError: invalid syntax
it still doesn't work, so I think our lambdify cannot handle this yet.
It think it'd be a useful to have this feature though.
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
-~----------~----~----~----~------~----~------~--~---