# vector-with-numpy-and-sympy.ipynb

to vector manager

In [1]:
import numpy as np
from sympy.abc import a, b, c, x, y, z, i, j, k
from sympy import Matrix, Eq
from sympy.vector import CoordSys3D, matrix_to_vector


## Numpy

In [2]:
v1 = np.array([a, b, c])
v2 = np.array([x, y, z])

In [3]:
np.dot(v1, v2)

Out[3]:
$\displaystyle a x + b y + c z$
In [4]:
np.cross(v1, v2)

Out[4]:
array([b*z - c*y, -a*z + c*x, a*y - b*x], dtype=object)

## Sympy-2D

In [23]:
u1 = Matrix([a, b])
u2 = Matrix([x, y])

In [25]:
display(u1, u2)

$\displaystyle \left[\begin{matrix}a\\b\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}x\\y\end{matrix}\right]$
In [27]:
u3 = u1.dot(u2)
u3

Out[27]:
$\displaystyle a x + b y$
u3 = np.cross(u1.T, u2) u3
In [ ]:


In [13]:
v21 = v2
v21

Out[13]:
$\displaystyle \left[\begin{matrix}x\\y\end{matrix}\right]$
In [15]:
display(v11, v21)

$\displaystyle \left[\begin{matrix}a & b\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}x\\y\end{matrix}\right]$
v4 = v21.cross(v11) v4v4 = v11.cross(v21) v4
In [19]:
C = CoordSys3D('C')

In [20]:
v3 = matrix_to_vector(v1, C)
display(v3)

$\displaystyle (a)\mathbf{\hat{i}_{C}} + (b)\mathbf{\hat{j}_{C}}$
In [21]:
v4 = matrix_to_vector(v2, C)
display(v4)

$\displaystyle (x)\mathbf{\hat{i}_{C}} + (y)\mathbf{\hat{j}_{C}}$
In [22]:
v5 = v3.cross(v4)
v5

Out[22]:
$\displaystyle (a y - b x)\mathbf{\hat{k}_{C}}$
In [ ]:


In [ ]:



## Sympy-3D

In [35]:
v1 = Matrix([a, b, c])
v2 = Matrix([x, y, z])

In [36]:
display(v1, v2)

$\displaystyle \left[\begin{matrix}a\\b\\c\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}x\\y\\z\end{matrix}\right]$
In [37]:
v3 = v1.dot(v2)
v3

Out[37]:
$\displaystyle a x + b y + c z$
In [38]:
v4 = v1.cross(v2)
v4

Out[38]:
$\displaystyle \left[\begin{matrix}b z - c y\\- a z + c x\\a y - b x\end{matrix}\right]$
In [39]:
C = CoordSys3D('C')

In [40]:
v3 = matrix_to_vector(v1, C)
display(v3)

$\displaystyle (a)\mathbf{\hat{i}_{C}} + (b)\mathbf{\hat{j}_{C}} + (c)\mathbf{\hat{k}_{C}}$
In [41]:
v4 = matrix_to_vector(v2, C)
display(v4)

$\displaystyle (x)\mathbf{\hat{i}_{C}} + (y)\mathbf{\hat{j}_{C}} + (z)\mathbf{\hat{k}_{C}}$
In [42]:
v5 = v3.cross(v4)
v5

Out[42]:
$\displaystyle (b z - c y)\mathbf{\hat{i}_{C}} + (- a z + c x)\mathbf{\hat{j}_{C}} + (a y - b x)\mathbf{\hat{k}_{C}}$
In [ ]:


In [ ]:



## Sympy-2D as 3D

In [43]:
v1 = Matrix([a, b, 0])
v2 = Matrix([x, y, 0])

In [44]:
display(v1, v2)

$\displaystyle \left[\begin{matrix}a\\b\\0\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}x\\y\\0\end{matrix}\right]$
In [45]:
v3 = v1.dot(v2)
v3

Out[45]:
$\displaystyle a x + b y$
In [46]:
v4 = v1.cross(v2)
v4

Out[46]:
$\displaystyle \left[\begin{matrix}0\\0\\a y - b x\end{matrix}\right]$
In [51]:
C = CoordSys3D('')

In [52]:
v3 = matrix_to_vector(v1, C)
display(v3)

$\displaystyle (a)\mathbf{\hat{i}_{}} + (b)\mathbf{\hat{j}_{}}$
In [53]:
v4 = matrix_to_vector(v2, C)
display(v4)

$\displaystyle (x)\mathbf{\hat{i}_{}} + (y)\mathbf{\hat{j}_{}}$
In [54]:
v5 = v3.cross(v4)
v5

Out[54]:
$\displaystyle (a y - b x)\mathbf{\hat{k}_{}}$
In [ ]:


In [ ]:


In [ ]: