today task make histogram represent operation of a^n matrix, specific entries in matrix.
for example, have matrix rows sum one. first entry specific decimal number. however, if raise matrix 2nd power, first entry becomes else, , if raise matrix 3rd power, changes again, etc - ad nauseum, , that's need plot.
right attempt create empty list, , use loop add entries result matrix multiplication list. however, print result final matrix multiplication list, rather printing value @ each iteration.
here's specific bit of code i'm talking about:
print("the intial probability matrix.") print(tabulate(matrix)) baseprob = [] in range(1000): matrix_n = numpy.linalg.matrix_power(matrix, s) baseprob.append(matrix_n.item(0)) print(baseprob) print("the final probability matrix.") print(tabulate(matrix_n)) here full code, output got.
of course prints final value, doing same operation, matrix^s, 1000 times. need have s change each of 1000 times.
if want calculate values in location matrix(0) matrix^i i each value 1 s (your final power) do:
baseprob = [] in range(1,s): #changed range 1-s instead of 1000 #must use loop variable here, not s (s same) matrix_n = numpy.linalg.matrix_power(matrix, i) baseprob.append(matrix_n.item(0)) then baseprob hold matrix(0) matrix^1, matrix^2, etc. way matrix^s.
Comments
Post a Comment