Can sympy manipulate vector expressions?

101 views
Skip to first unread message

Frank Senkel

unread,
May 29, 2025, 5:28:21 PMMay 29
to sympy
Does sympy handle vector expressions vs instances of specific vectors?..so AxBxC vs [a1,a2,a3] x [b1, b2, b3]...something like this. 

CDN media

Donaldson Tan

unread,
Jul 19, 2025, 3:19:24 AMJul 19
to sympy
A vector is actually a single column Matrix object. Just try on the Sympy shell.

Jason Moore

unread,
Jul 19, 2025, 3:25:00 AMJul 19
to sy...@googlegroups.com
I do not think there is a VectorSymbol type of object. If there was you could imagine doing things like:

R = VectorSymbol('R', 3)
r = VectorSymbol('r', 3)
R.diff(t).cross(r.diff(t))

We do have a MatrixSymbol object that may do what you desire. You can create nx1 column matrices and then do such operations.

Jason


On Thu, May 29, 2025 at 11:28 PM Frank Senkel <frank....@gmail.com> wrote:
Does sympy handle vector expressions vs instances of specific vectors?..so AxBxC vs [a1,a2,a3] x [b1, b2, b3]...something like this. 

CDN media

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/sympy/b22199b5-810b-4371-8479-eabd71e30d0dn%40googlegroups.com.

Aaron Meurer

unread,
Jul 19, 2025, 12:10:36 PMJul 19
to sy...@googlegroups.com
I would also suggest using matrix expressions for this. The main issue
is that matrix expressions currently don't have a Cross operation. It
wouldn't be too hard to make one by subclassing MatrixExpr. I would
suggest opening an issue about this.

The diff thing is another issue because currently there isn't a way to
represent functions in the matrix expressions
https://github.com/sympy/sympy/issues/5855
https://github.com/sympy/sympy/issues/19265

Aaron Meurer

On Sat, Jul 19, 2025 at 1:24 AM Jason Moore <moore...@gmail.com> wrote:
>
> I do not think there is a VectorSymbol type of object. If there was you could imagine doing things like:
>
> R = VectorSymbol('R', 3)
> r = VectorSymbol('r', 3)
> R.diff(t).cross(r.diff(t))
>
> We do have a MatrixSymbol object that may do what you desire. You can create nx1 column matrices and then do such operations.
>
> Jason
> moorepants.info
> +01 530-601-9791
>
>
> On Thu, May 29, 2025 at 11:28 PM Frank Senkel <frank....@gmail.com> wrote:
>>
>> Does sympy handle vector expressions vs instances of specific vectors?..so AxBxC vs [a1,a2,a3] x [b1, b2, b3]...something like this.
>>
>> --
>> You received this message because you are subscribed to the Google Groups "sympy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
>> To view this discussion visit https://groups.google.com/d/msgid/sympy/b22199b5-810b-4371-8479-eabd71e30d0dn%40googlegroups.com.
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/sympy/CAP7f1AiS2juGowfs0%3DYQcyR4mgaDZsHjRoZtwXAWEToi2r8nvg%40mail.gmail.com.

Peter Stahlecker

unread,
Jul 19, 2025, 12:44:20 PMJul 19
to sympy
In sympy.physics.mechanics, I can create, say, three point P1, P2, P3
make 
u = P1.pos_from(P2)
v = P2.pos_from(P3)

and can get
w = u.cross(v)

but maybe I am missing a point.

Aaron Meurer

unread,
Jul 21, 2025, 12:08:47 PMJul 21
to sy...@googlegroups.com
Yes, I think the stuff in mechanics is the best way to achieve what
you are looking for right now. It might be good to try to unify some
of this stuff at some point, since much of what is in mechanics isn't
really specific to mechanics or even physics.

Aaron Meurer
> To view this discussion visit https://groups.google.com/d/msgid/sympy/70440eaa-7bc7-4ab8-a5d6-06bc7abf53f9n%40googlegroups.com.

Frank Senkel

unread,
Jul 21, 2025, 1:09:12 PMJul 21
to sympy
I was hoping to be able to manipulate vector objects in lieu of arrays of components. When you work on a component basis, it's gets hard to recognize cross and dot products when there chain of dots and crosses. It seems like they could be another symbol class that has a slightly different set of rules. I wonder if sagemath has something, although using sagemath seems to be way more complicated...

I am using the mechanics pkg (it's awesome!). I going through a text on Kane's method and trying to do every problem in the book with sympy. I run into difficulties with some of the proofs where you have to expand multiple dot product, cross products, and triple products. Currently I default to a tablet and just do it by hand.

I can't imagine grinding on all the algebra by hand...you'd need to take my belt and shoelaces...

Peter Stahlecker

unread,
Jul 21, 2025, 1:15:52 PMJul 21
to sympy
I have used sympy.physics.mechanics, Kane's method, on many, surely over 100 or 200 simulations. As you say, it is awsome!
Which book are yopu referring to, if I may ask? Calos Roithmyr's book?

Peter Stahlecker

unread,
Jul 21, 2025, 2:05:53 PMJul 21
to sympy
Carlos Roithmayr

Frank Senkel

unread,
Jul 21, 2025, 2:38:26 PMJul 21
to sympy
Yes, Carlos Roithmayr...though I have to admit I balked on problems related to P3.15, just too many substitutions, I'll probable go back and get it when I'm done.

I'm not sure how I feel about the text, it feels more like a cook book, and doesn't really give insights as to why he chose this method. Ginsberg is pretty good for that. All the variable changes, and call backs to prior problems are bit annoying. But luckily it provides solutions to all the problems, although he seems to make some non-intuitive choices in how the final solution is presented...I'm on problem set 12, and I'm hoping to grind through the whole text...

Peter Stahlecker

unread,
Jul 21, 2025, 2:51:03 PMJul 21
to sympy
Yes, it is a bit abstract. I did not study the whole book, I just wanted to find out about complex (=nonlinear) velocity constraints.
As I understand Kane's method, you just follow the rules - and out come Newton-Euler's equations! The beauty is, that forces which do not do work fall out.
Reply all
Reply to author
Forward
0 new messages