# laplace transform sagemaths

I have a polynomial expression P(x) in x and I want to evaluate it for x=A a matrix. I tried

P(x).substitute(x=A)


but I have error :

TypeError: Cannot convert sage.matrix.matrix_integer_dense.Matrix_integer_dense to sage.symbolic.expression.Expression


How can I proceed? Is there a coercion possible. Thanks

edit retag close merge delete

Could you please provide the code to construct P, x and A so that we can reproduce your issue ?

Sort by » oldest newest most voted

The following worked for me:

(1) Using the polynomial (only algebraic expressions) $P$ in $x$ as a true polynomial over the base ring / field of the matrix $A$, in the following sample it is $\Bbb Z$:

R.<x> = PolynomialRing(ZZ)    # or also R.<x> = ZZ[]

P = x^2007 + 4*x + 1
A = matrix(2, 2, [0, -1, 1, 1])
P(A)


This gives:

sage: P(A)
[ 0 -4]
[ 4  4]
sage: A^2007 + 4*A + 1
[ 0 -4]
[ 4  4]


(2) Using a sage function $P$ of the argument $x$:

def P(x):
return x^2007 + 4*x + 1

A = matrix(2, 2, [0, -1, 1, 1])
P(A)


This gives the same result.

(3) Using an expression (which in a more general setting may contain $\sin$, $\log$, $\exp$, ... but for the code below should not...) in the variable $x$, well we cheat and build the polynomial for $f$, we are now in the case $A$, then plug in the matrix $A$:

x = var('x')
A = matrix(2, 2, [0, -1, 1, 1])
f = x^2007 + 4*x + 1

f.polynomial(ZZ)(A)


Same result.

more