Ask Your Question

Revision history [back]

One way would be to use the "symbolic n-th power of a matrix".

Define the matrix m with coefficients in $\overline{mathbb{Q}}$, the field of algebraic numbers:

sage: phi = matrix(QQbar, [[1/sqrt(2)],[i]])
sage: m = phi * phi.C.T
sage: m
[                   1/2 -0.7071067811865475?*I]
[ 0.7071067811865475?*I                      1]

Define a symbolic variable in Sage's symbolic ring:

sage: n = SR.var('n')

Take the n-th power of m:

sage: mn = m^n
sage: mn
[           1/3*3^n/2^n -1/3*I*sqrt(2)*3^n/2^n]
[ 1/3*I*sqrt(2)*3^n/2^n            2/3*3^n/2^n]

Substitute 1/2 to the exponent n:

sage: msqrt = mn.subs({n: 1/2})
sage: msqrt
[1/6*sqrt(3)*sqrt(2)      -1/3*I*sqrt(3)]
[      1/3*I*sqrt(3) 1/3*sqrt(3)*sqrt(2)]

The result has coefficients in Sage's symbolic ring.

To convert it to another ring, use change_ring:

sage: msqrt.change_ring(QQbar)
[   0.4082482904638630? -0.5773502691896258?*I]
[ 0.5773502691896258?*I    0.8164965809277260?]

Check that squaring the square root gives back the original matrix:

sage: msqrt^2
[           1/2 -1/2*I*sqrt(2)]
[ 1/2*I*sqrt(2)              1]

One way would be to use the "symbolic n-th power of a matrix".

Define the matrix m with coefficients in $\overline{mathbb{Q}}$, $\overline{mathbf{Q}}$, the field of algebraic numbers:

sage: phi = matrix(QQbar, [[1/sqrt(2)],[i]])
sage: m = phi * phi.C.T
sage: m
[                   1/2 -0.7071067811865475?*I]
[ 0.7071067811865475?*I                      1]

Define a symbolic variable in Sage's symbolic ring:

sage: n = SR.var('n')

Take the n-th power of m:

sage: mn = m^n
sage: mn
[           1/3*3^n/2^n -1/3*I*sqrt(2)*3^n/2^n]
[ 1/3*I*sqrt(2)*3^n/2^n            2/3*3^n/2^n]

Substitute 1/2 to the exponent n:

sage: msqrt = mn.subs({n: 1/2})
sage: msqrt
[1/6*sqrt(3)*sqrt(2)      -1/3*I*sqrt(3)]
[      1/3*I*sqrt(3) 1/3*sqrt(3)*sqrt(2)]

The result has coefficients in Sage's symbolic ring.

To convert it to another ring, use change_ring:

sage: msqrt.change_ring(QQbar)
[   0.4082482904638630? -0.5773502691896258?*I]
[ 0.5773502691896258?*I    0.8164965809277260?]

Check that squaring the square root gives back the original matrix:

sage: msqrt^2
[           1/2 -1/2*I*sqrt(2)]
[ 1/2*I*sqrt(2)              1]

One way would be to use the "symbolic n-th power of a matrix".

Define the matrix m with coefficients in $\overline{mathbf{Q}}$, QQbar, the field of algebraic numbers:

sage: phi = matrix(QQbar, [[1/sqrt(2)],[i]])
sage: m = phi * phi.C.T
sage: m
[                   1/2 -0.7071067811865475?*I]
[ 0.7071067811865475?*I                      1]

Define a symbolic variable in Sage's symbolic ring:

sage: n = SR.var('n')

Take the n-th power of m:

sage: mn = m^n
sage: mn
[           1/3*3^n/2^n -1/3*I*sqrt(2)*3^n/2^n]
[ 1/3*I*sqrt(2)*3^n/2^n            2/3*3^n/2^n]

Substitute 1/2 to the exponent n:

sage: msqrt = mn.subs({n: 1/2})
sage: msqrt
[1/6*sqrt(3)*sqrt(2)      -1/3*I*sqrt(3)]
[      1/3*I*sqrt(3) 1/3*sqrt(3)*sqrt(2)]

The result has coefficients in Sage's symbolic ring.

To convert it to another ring, use change_ring:

sage: msqrt.change_ring(QQbar)
[   0.4082482904638630? -0.5773502691896258?*I]
[ 0.5773502691896258?*I    0.8164965809277260?]

Check that squaring the square root gives back the original matrix:

sage: msqrt^2
[           1/2 -1/2*I*sqrt(2)]
[ 1/2*I*sqrt(2)              1]