# Determinant Function on Qp

See attachmentC:\fakepath\Screenshot (104).png

I basically have 2 matrices with entries in Qp. I cant exactly do Matrix2.charpoly() as this is det (xI-Matrix2) and I want determinant of (I-xMatrix2). So I decided to just type det(I-x*Matrix2) but it gives me error. Is there a way to fix this?

If you want me to be honest, I get an error just from I-x*Matrix2. So it might not even be the determinant function.

edit retag close merge delete

Could you please provide your code so that we can understand ? The picture does not show the whole construction.

Sort by » oldest newest most voted

Given the picture, i have to guess your construction (tell ):

Your field K :

sage: K = Qp(5,prec=70)
sage: K
5-adic Field with capped relative precision 70


Your matrix I (which is the identity) :

sage: I = matrix.identity(K,15)


There is no information about the construction of Matrix2, hence, i will pick one randomly:

sage: M = I.parent()
sage: M
Full MatrixSpace of 15 by 15 dense matrices over 5-adic Field with capped relative precision 70
sage: Matrix2 = M.random_element()


On my installation,

sage: Matrix2.charpoly()


works well.

The folowing does not work:

sage: x*Matrix2


because, by default x is a symbol, to be used in symbolic expressions like sin(x)*sqrt(2).

What you might want is a polynomial indeterminate. The following non-Pythonic constructions builds both the polynomial ring R and the indeterminate x

sage: R.<x> = K[]
sage: R
Univariate Polynomial Ring in x over 5-adic Field with capped relative precision 70


WIth such a x, you can do:

sage: det(I - x*Matrix2)


The difference with the previous charpoly result seem to be some residual things due to bounded precision:

sage: det(I - x*Matrix2) - Matrix2.charpoly()
O(5^-1843)*x^15 + O(5^-1813)*x^14 + O(5^-1585)*x^13 + O(5^-1544)*x^12 + O(5^-1316)*x^11 + O(5^-1275)*x^10 + O(5^-1047)*x^9 + O(5^-1006)*x^8 + O(5^-1006)*x^7 + O(5^-1047)*x^6 + O(5^-1275)*x^5 + O(5^-1316)*x^4 + O(5^-1544)*x^3 + O(5^-1585)*x^2 + O(5^-1813)*x + O(5^-1843)

more

Great thanks. I have a question on this. Suppose I have a matrix with rational entries. So let's say Matrix is = [a, b] [c ,d]. How can I quickly make Sage consider this over K, the p adic integers. Do I have to explicitly type out K(a), K(b), K(c), K(d). This is really annoying if the matrix is huge

Having defined a matrix m over QQ, and a field K of p-adic numbers, use m.change_ring(K).