import numpy as np
from numpy.linalg import matrix_power
# Define the matrix
# States order: N, H, HH, T, TT, S
P = np.array([
[0, 1/2, 0, 1/2, 0, 0 ], # From N
[0, 0, 1/2, 1/2, 0, 0 ], # From H
[0, 0, 0, 1/2, 0, 1/2], # From HH
[0, 1/2, 0, 0, 1/2, 0 ], # From T
[0, 1/2, 0, 0, 0, 1/2], # From TT
[0, 0, 0, 0, 0, 1 ] # From S
])
# Number of powers to calculate
n = 11 # Change this value to compute up to P^n
# Compute and print powers of P
for i in range(1, n + 1):
P_i = matrix_power(P, i)
print(f"P^{i} using NumPy:\n", P_i)