Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I have a vector $Z_n$ with and I want to transform it into another vector using this formula:


The problem is that I am not quite sure how to get that $t-2$ lag in there. I see how I could do it with a For loop but that doesn't seem like a very Mathematica way of doing it.

share|improve this question
The question is not very clear. What do mean by this lag in a vector addiction? If you are talking about some recurrence relation you need to give initial conditions for that. – PlatoManiac Feb 16 '12 at 21:39
up vote 11 down vote accepted

Assuming that the vector is called z and $n$ in your formula is the integer index of vector elements, use

x = Drop[z, 2] + 0.7 Drop[z, -2]

This adds the vector (sans the last two elements) to the vector times 0.7 with the first two elements removed (i.e. shifted by two elements to the left). Of course the result will be 2 elements shorter than the original. If this is not desired, you need to decide what $Z_0$ and $Z_{-1}$ should be and pad (PadLeft) z with these values.

This is likely the fastest possible solution in Mathematica.


Another, also very fast possibility is

x = ListCorrelate[{0.7, 0, 1}, z]

ListCorrelate has settings for padding the arrays as well, if needed.

share|improve this answer
ListCorrelate looks to be exactly what I'm looking for. – Mr Alpha Feb 17 '12 at 8:45

Your formula is not really correct. It lags of initial conditions but maybe this example helps you:

z[0] = {1, 2, 3};
z[1] = {4, 4, 4};
z[2] = {3, 2, 1};
z[n_ /; n > 2] := z[n - 1] + 0.7 z[n - 2]


Out[8]= {11.96, 9.56, 7.16}
share|improve this answer
And I assumed it is a vector-variable which depends on the time.. – halirutan Feb 16 '12 at 22:07

If by "delay" you mean you're trying to implement some equation of motion, maybe this will help:

 v = v + .1 (p - q) - .5 v;
 q = q + .1 v;
 Graphics[{Red, Point[q]}, PlotRange -> {{-1, 1}, {-1, 1}}],
 {{p, {0, 0}}, {-1, -1}, {1, 1}, Locator},
 ControlPlacement -> Automatic,
 SynchronousUpdating -> True, SaveDefinitions -> True, 
 Initialization :> (q = {0, 0}; v = {0, 0}), 
 FrameLabel -> "The red dot will follow you with some delay"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.