Ondrej Certik wrote:
> 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?
Ahh, yes, silly mistake...
[snip]
> 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.
Digging a bit into sympy looks like this is beyond my immediate
abilities -- Python will of course evaluate X[0] in the Matrix
definition above to x (for the case above). So, I think there'd need to
be a way to tell sympy "element zero of vector X" without having it
dereferenced. Thus, rather than __getattr__ or the equivalent, something
like X.get_component(0), which would return some kind of deferred
reference to component zero of X.
x,y,z = symbols('xyz')
X=Matrix([x,y,z])
M=Matrix([[X.get_component(0)**2, ...
Or, perhaps a "DeferredMatrix" that implements this automatically?
X=DeferredMatrix()
M=Matrix([[X[0]**2, ...
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---