Skip to content

Commit

Permalink
Merge pull request #2263 from Upabjojr/matrix_exp
Browse files Browse the repository at this point in the history
Allowing exp( ) function to act on a Matrix
  • Loading branch information
asmeurer committed Jul 12, 2013
2 parents c7fbd90 + a857e7e commit c9611ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions sympy/functions/elementary/exponential.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ def eval(cls, arg):
if out:
return Mul(*out)*cls(Add(*add), evaluate=False)

elif arg.is_Matrix:
from sympy import Matrix
return arg.exp()

@property
def base(self):
"""
Expand Down
10 changes: 6 additions & 4 deletions sympy/matrices/matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3538,10 +3538,11 @@ def row_join(self, rhs):
raise ShapeError(
"`self` and `rhs` must have the same number of rows.")

newmat = self.zeros(self.rows, self.cols + rhs.cols)
from sympy.matrices import MutableMatrix
newmat = MutableMatrix.zeros(self.rows, self.cols + rhs.cols)
newmat[:, :self.cols] = self
newmat[:, self.cols:] = rhs
return newmat
return type(self)(newmat)

def col_join(self, bott):
"""Concatenates two matrices along self's last and bott's first row
Expand Down Expand Up @@ -3649,12 +3650,13 @@ def col_insert(self, pos, mti):
if self.rows != mti.rows:
raise ShapeError("self and mti must have the same number of rows.")

newmat = self.zeros(self.rows, self.cols + mti.cols)
from sympy.matrices import MutableMatrix
newmat = MutableMatrix.zeros(self.rows, self.cols + mti.cols)
i, j = pos, pos + mti.cols
newmat[:, :i] = self[:, :i]
newmat[:, i:j] = mti
newmat[:, j:] = self[:, i:]
return newmat
return type(self)(newmat)

def replace(self, F, G, map=False):
"""Replaces Function F in Matrix entries with Function G.
Expand Down
6 changes: 4 additions & 2 deletions sympy/matrices/tests/test_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,11 +1450,13 @@ def test_Matrix_berkowitz_charpoly():

def test_exp():
m = Matrix([[3, 4], [0, -2]])
assert m.exp() == \
Matrix([[exp(3), -4*exp(-2)/5 + 4*exp(3)/5], [0, exp(-2)]])
m_exp = Matrix([[exp(3), -4*exp(-2)/5 + 4*exp(3)/5], [0, exp(-2)]])
assert m.exp() == m_exp
assert exp(m) == m_exp

m = Matrix([[1, 0], [0, 1]])
assert m.exp() == Matrix([[E, 0], [0, E]])
assert exp(m) == Matrix([[E, 0], [0, E]])


def test_has():
Expand Down

0 comments on commit c9611ed

Please sign in to comment.