2

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[0] 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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
arrowdog
  • 23
  • 2

2 Answers2

6
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]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
2

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

If you want to keep the values of u[1], u[2], etc.:

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

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[0], 10]
]

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

JungHwan Min
  • 4,664
  • 1
  • 22
  • 36
  • I would really like the 3d plot to be a contour plot that shows each iteration, u[1], u[2], u[3], ... progressing through time, not stacked on top of one another. Not sure how to do this in this instance. – arrowdog Feb 18 '16 at 04:30