Search code examples
pythonmatrixsympysymbols

SymPy: Replace a symbol inside a matrix


I have a matrix that contains symbols:


t = sympy.symbols("t")
A = sympy.Matrix([[np.exp(t),1,-1)], [0,t,0], [0,t+1,0]])

I want to replace all the symbols "t" with a number.

Thank you in advance.


Solution

  • A = sympy.Matrix([[sympy.exp(t),1,-1], [0,t,0], [0,t+1,0]]) # fixing your expression
    print(A.subs(t, 5))
    

    Which gives

    Matrix([
    [exp(5), 1, -1],
    [     0, 5,  0],
    [     0, 6,  0]])