# Repeated multiplication of a square matrix and a column vector in Mathematica

I am very new to Mathematica and StackExchange, so pardon me if I am repeating a question that has already been answered. I am trying to use Mathematica to do the following: u[n+1] = A.u[n] where A is a square tridiagonal matrix and u is a column vector. I want to be able to run this for any number of iterations, as many as I need. I then want to do a 3d plot of the results. My skills are very rudimentary. I would include what I already tried, but I havent been able to do any of it yet.

• Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Feb 17 '16 at 23:57
• For starters NestList[A.#&, u,5] – Dr. belisarius Feb 17 '16 at 23:58
• To keep the syntax close to what you have written: u[n_] := u[n] = a.u[n - 1]; Then specify a and u and ask for u or u. – bill s Feb 18 '16 at 0:02
• Presumably, since A is a fixed matrix, you'll want to use the action form of MatrixPower[]: MatrixPower[A, 5, u]. – J. M. is away Feb 18 '16 at 1:00
• No, I am using the explicit finite difference method to solve the heat equation. I am comparing that to solving the heat equation using Fourier Series. – arrowdog Feb 18 '16 at 4:24

As @Dr. belisarius stated, NestList[A.#&, u,5] would work. (# and & are pure functions. This guide may help)

If you want to keep the values of u, u, etc.:

u[n_] := u[n] = A . u[n - 1];
u = {x, y, z}; (* your definition here *)
u


The u[n] = part after u[n_] := is optional (memoization), but it is a good practice to have it if you have a recursion formula. It saves memory by preventing redundant computations.

Then for a 3D plot: (replace 10 with whatever number of point you want)

ListPointPlot3D[Table[u[n], {n, 0, 10}]


-

Edit: A useful function to use could be NestList. It performs a given operation a given number of times and outputs all of the steps. For example, NestList[f, x, 3] gives {x, f[x], f[f[x]], f[f[f[x]]]}.

Use this instead if you do not want to keep the values of u[n]:

ListPointPlot3D[
NestList[Function[vector, A . vector], u, 10]
]


You could replace Function[...] with its pure-function counterpart, A.#&.

• I would really like the 3d plot to be a contour plot that shows each iteration, u, u, u, ... progressing through time, not stacked on top of one another. Not sure how to do this in this instance. – arrowdog Feb 18 '16 at 4:30
a = RotationMatrix[Pi/20, {0, 1, 1}] // N;
start = {1, 0, 0};
Graphics3D[{Blue, Arrowheads[.03], Arrow@Partition[#, 2, 1], Red,
PointSize[Medium], Point@#, Green, PointSize[.03],
Point@start}] &@NestList[a.# &, start, 40] 