In Matlab / Octave, you can directly perform matrix multiplication using the * operator. The end keyword is used to refer to the last element of a vector or the last row/column of a matrix. |
|
- M = [0.56 ,0.56 ,0.56 ,0.56 ,0.56 ,0.56 ,0.56 ,0;
- 0.44 ,0 ,0 ,0 ,0 ,0 ,0 ,0;
- 0 ,0.44 ,0 ,0 ,0 ,0 ,0 ,0;
- 0 ,0 ,0.44 ,0 ,0 ,0 ,0 ,0;
- 0 ,0 ,0 ,0.44 ,0 ,0 ,0 ,0;
- 0 ,0 ,0 ,0 ,0.44 ,0 ,0 ,0;
- 0 ,0 ,0 ,0 ,0 ,0.44 ,0 ,0;
- 0 ,0 ,0 ,0 ,0 ,0 ,0.44 ,1];
-
- V = [1;0;0;0;0;0;0;0];
- Out = M^1500 * V;
- Out(end)
复制代码 In Mathematica, MatrixPower[M, n] is used to raise a matrix M to the power n , and Last[out] or out[[-1]] is equivalent to Out(end) in MATLAB, giving the last element of the vector out .
- M = {{0.56, 0.56, 0.56, 0.56, 0.56, 0.56, 0.56, 0},
- {0.44, 0, 0, 0, 0, 0, 0, 0},
- {0, 0.44, 0, 0, 0, 0, 0, 0},
- {0, 0, 0.44, 0, 0, 0, 0, 0},
- {0, 0, 0, 0.44, 0, 0, 0, 0},
- {0, 0, 0, 0, 0.44, 0, 0, 0},
- {0, 0, 0, 0, 0, 0.44, 0, 0},
- {0, 0, 0, 0, 0, 0, 0.44, 1}};
- V = {1, 0, 0, 0, 0, 0, 0, 0};
- out = MatrixPower[M, 1500].V;
- out[[-1]]
复制代码 |