On Mon, May 26, 2008 at 08:43:02AM -0700, astozzia wrote:
>
> hey all!
>
> I have a vector with symbolic variables in it:
> In [1]: from sympy import *
> In [2]: import scipy as s
> In [3]: t,x,z,phi = symbols('t','x','z','phi')
> In [4]: vec = s.array([cos(phi(t)),x(t),z(t)])
>
> Now, I define the derivative w.r.t time 't'
> In [5]: dvec = diff(vec,t)
> In [6]: dvec
> Out[6]: [-sin(phi(t))*D(phi(t), t), D(x(t), t), D(z(t), t)]
>
> I need to compute the unit vector along the direction of 'dvec', but I
> get the following error:
>
> In [7]: evec = dvec/sqrt(s.dot(dvec,dvec))
> TypeError: unsupported operand type(s) for /: 'list' and 'Pow'

The problem is that

In [26]: type(dvec)
Out[26]: <type 'list'>

so you have to convert your 'vector' to a sympy

In [27]: mdvec=Matrix(dvec).T

In [31]: mdvec*(1/x**2)
Out[31]:
⎡           d                   d                   d       ⎤
⎢-sin(φ(t))*──(φ(t))            ──(x(t))            ──(z(t))⎥
⎢           dt                  dt                  dt      ⎥
⎢───────────────────            ────────            ────────⎥
⎢          2                        2                   2   ⎥
⎣         x                        x                   x    ⎦

(subs the x**2 by your sqrt(...))

The In[31] must be so unconvenient because otherwise the '/' fails.
It seems to be a bug.

Or you can use the scipy array:
In [32]: advec=s.array(dvec)

In [33]: advec/x**2
Out[33]: [-x**(-2)*sin(phi(t))*D(phi(t), t) x**(-2)*D(x(t), t) x**(-2)*D(z(t), 
t)]

I hope that helps.


By,  Friedrich



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to