Repository: sympy/sympy

Issue:
MatrixSymbol's are not evaluated
This issue was discussed in Google Group: https://groups.google.com/forum/#!topic/sympy/cHiX1dY5nUM

Here is simple test:
```
from sympy import MatrixSymbol, ImmutableMatrix

u = MatrixSymbol('u', 2,1)

print "\n\ntest1:"
print  u.subs(u, ImmutableMatrix([3,5]))[0,0]   # evaluates fine

print "\n\ntest2:"
print  u[0,0].subs(u, ImmutableMatrix([3,5]))  # do not evaluate

print "\n\ntest3:"
print  u[0,0].subs(u, ImmutableMatrix([3,5])).evalf() # sill not evaluated

print "\n\ntest4:"
print  u[0,0].subs(u, ImmutableMatrix([3,5])).doit() # sill not evaluated

print "\n\ntest5:"
print  u[0,0].subs(u, ImmutableMatrix([3,5])).doit().evalf() # sill not evaluated

print "\n\ntest6:"
print  u[0,0].subs(u, ImmutableMatrix([3,5])).evalf().doit() # sill not evaluated
```


Here is an output of the code:
```
test1:
3


test2:
Matrix([
[3],
[5]])[0, 0]


test3:
Matrix([
[3],
[5]])[0, 0]


test4:
Matrix([
[3],
[5]])[0, 0]


test5:
Matrix([
[3],
[5]])[0, 0]


test6:
Matrix([
[3],
[5]])[0, 0]

```

The expected result is 3 in all six tests (as in test1).


Discussion:

Patch:
diff --git a/sympy/matrices/expressions/matexpr.py b/sympy/matrices/expressions/matexpr.py
index 01b7420823..b07b3750ad 100644
--- a/sympy/matrices/expressions/matexpr.py
+++ b/sympy/matrices/expressions/matexpr.py
@@ -322,6 +322,14 @@ class MatrixElement(Expr):
     j = property(lambda self: self.args[2])
     _diff_wrt = True
 
+    def doit(self, **kwargs):
+        deep = kwargs.get('deep', True)
+        if deep:
+            args = [arg.doit(**kwargs) for arg in self.args]
+        else:
+            args = self.args
+        return args[0][args[1], args[2]]
+
 
 class MatrixSymbol(MatrixExpr):
     """Symbolic representation of a Matrix object


Test patch:
diff --git a/sympy/matrices/expressions/tests/test_matrix_exprs.py b/sympy/matrices/expressions/tests/test_matrix_exprs.py
index 77a8f1f9ed..d1f0dcbb23 100644
--- a/sympy/matrices/expressions/tests/test_matrix_exprs.py
+++ b/sympy/matrices/expressions/tests/test_matrix_exprs.py
@@ -207,3 +207,9 @@ def test_single_indexing():
 
 def test_MatrixElement_diff():
     assert (A[3, 0]*A[0, 0]).diff(A[0, 0]) == A[3, 0]
+
+
+def test_MatrixElement_doit():
+    u = MatrixSymbol('u', 2, 1)
+    v = ImmutableMatrix([3, 5])
+    assert u[0, 0].subs(u, v).doit() == v[0, 0]