Ask Your Question
0

laplace transform sagemaths

asked 2023-02-02 20:53:17 +0100

updated 2023-02-06 18:59:01 +0100

dan_fulea gravatar image

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 flag offensive close merge delete

Comments

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

tmonteil gravatar imagetmonteil ( 2023-02-05 09:31:21 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-02-06 19:23:22 +0100

dan_fulea gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2023-02-02 20:53:17 +0100

Seen: 104 times

Last updated: Feb 06 '23