scientific-programming-exer.../ex_43.py

16 lines
349 B
Python

import numpy as np
P = np.array(
[ [1/6, 1/6, 1/6, 1/6, 1/6, 0]
, [1/6, 1/6, 1/6, 1/6, 1/6, 0]
, [1/6, 1/6, 1/6, 1/6, 1/6, 0]
, [1/6, 1/6, 1/6, 1/6, 1/6, 0]
, [1/6, 1/6, 1/6, 1/6, 1/6, 1/10]
, [1/6, 1/6, 1/6, 1/6, 1/6, 9/10]])
print(P.shape)
v = np.array([0, 1, 0, 0, 0, 0])
w = np.dot(np.linalg.matrix_power(P, 4), v)
print(w)
print(w[-1])