2 added timing data
source | link

Using Nest[] is one option if you're applying general operations. For your specific example, you can also use MatrixPower[]:

a = RandomReal[1, {5, 5}];
x1 = RandomReal[1, 5];

x2 = a.x1;
x3 = a.x2;
x4 = a.x3;
x5 = a.x4;

Nest[Dot[a, #] &, x1, 4] == x5
(* True *)

MatrixPower[a, 4].x1 == x5
(* True *)

For larger matrices, MatrixPower[] is a bit faster:

a = RandomReal[1, {100, 100}];
x = RandomReal[1, 100];
x1 = x;

First@Timing[For[i = 1, i <= 500, i++, x = a.x;]]
First@Timing[nestx = Nest[Dot[a, #] &, x1, 500];]
First@Timing[powerx = MatrixPower[a, 500].x1;]
x == nestx == powerx
(* 6.860000 *)
(* 6.820000 *)
(* 3.580000 *)
(* True *)
a = RandomReal[1, {5, 5}];
x1 = RandomReal[1, 5];

x2 = a.x1;
x3 = a.x2;
x4 = a.x3;
x5 = a.x4;

Nest[Dot[a, #] &, x1, 4] == x5
(* True *)

MatrixPower[a, 4].x1 == x5
(* True *)

Using Nest[] is one option if you're applying general operations. For your specific example, you can also use MatrixPower[]:

a = RandomReal[1, {5, 5}];
x1 = RandomReal[1, 5];

x2 = a.x1;
x3 = a.x2;
x4 = a.x3;
x5 = a.x4;

Nest[Dot[a, #] &, x1, 4] == x5
(* True *)

MatrixPower[a, 4].x1 == x5
(* True *)

For larger matrices, MatrixPower[] is a bit faster:

a = RandomReal[1, {100, 100}];
x = RandomReal[1, 100];
x1 = x;

First@Timing[For[i = 1, i <= 500, i++, x = a.x;]]
First@Timing[nestx = Nest[Dot[a, #] &, x1, 500];]
First@Timing[powerx = MatrixPower[a, 500].x1;]
x == nestx == powerx
(* 6.860000 *)
(* 6.820000 *)
(* 3.580000 *)
(* True *)
1
source | link

a = RandomReal[1, {5, 5}];
x1 = RandomReal[1, 5];

x2 = a.x1;
x3 = a.x2;
x4 = a.x3;
x5 = a.x4;

Nest[Dot[a, #] &, x1, 4] == x5
(* True *)

MatrixPower[a, 4].x1 == x5
(* True *)