'Returns the matrix form of the dyadic with respect to one or two
coordinate systems.
Parameters
system : CoordSys3D
The coordinate system that the rows and columns of the matrix
correspond to. If a second system is provided, this
only corresponds to the rows of the matrix.
second_system : CoordSys3D, optional, default=None
The coordinate system that the columns of the matrix correspond
to.
Examples
>>> from sympy.vector import CoordSys3D
>>> N = CoordSys3D(\'N\')
>>> v = N.i + 2*N.j
>>> d = v.outer(N.i)
>>> d.to_matrix(N)
Matrix([
[1, 0, 0],
[2, 0, 0],
[0, 0, 0]])
>>> from sympy import Symbol
>>> q = Symbol(\'q\')
>>> P = N.orient_new_axis(\'P\', q, N.k)
>>> d.to_matrix(N, P)
Matrix([
[  cos(q),   -sin(q), 0],
[2*cos(q), -2*sin(q), 0],
[       0,         0, 0]])'

def to_matrix(self, system, second_system=None):

    if (second_system is None):
        second_system = system
    return Matrix([i.dot(self).dot(j) for i in system for j in second_system]).reshape(3, 3)
