pythonvectorsympyequationbasis

Geting the scalars of one single vector basis using Sympy


I'm new to the sympy library and I have a relatively simple question. I am writing a 3D vector as follows

from sympy.vector import CoordSys3D
N = CoordSys3D('N')
v = 1*N.i + 4*N.j + 5*N.k

I would like to have access to the scalar from just one of the bases for exemple:

The command v[0] = 1 or v[1] = 4.

Its that possible using Sympy?


Solution

  • You can use dot to extract a component:

    In [57]: from sympy.vector import CoordSys3D, dot
        ...: N = CoordSys3D('N')
        ...: v = 1*N.i + 4*N.j + 5*N.k
    
    In [58]: v
    Out[58]: i_N + (4) j_N + (5) k_N
    
    In [59]: dot(v, N.j)
    Out[59]: 4