I am trying to compute the matrix B which has the following equation:
B = A^2
.
Assume that A is a matrix:
array([[1, 2], [3, 4]])
When I take the negative half power of this matrix in Matlab (A^-0.5)
. I get the following result:
ans =
0.1031 - 1.2474i 0.1502 + 0.5706i
0.2253 + 0.8559i 0.3284 - 0.3915i
However, in Python using the code (A**-0.5)
I get different results
array([[ 1. , 0.70710678],
[ 0.57735027, 0.5 ]]).
My question is how can I use Python to replicate the Matlab output. I have tried numpy function numpy.linalg.matrix_power(M, n), but this fails as it only takes integers as a second argument, whereas I need a float. Thank you!!!
scipy.linalg
supports fractional matrix powers:
import numpy as np
from scipy.linalg import fractional_matrix_power
A = np.array([[1, 2], [3, 4]])
fractional_matrix_power(A, -0.5)
# array([[ 0.10306396-1.24742804j, 0.15020820+0.5706074j ],
# [ 0.22531231+0.8559111j , 0.32837626-0.39151694j]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With