# Iteration of function

May I ask how can we create iteration function using the previous data that was imported and calculated. I have tried using {i, ndata}, on the equation function but it wasn't working.

Data1 = Table[{rawdata[[i, 4]], rawdata[[i, 5]], rawdata[[i, 6]]}, {i,
ndata}] // MatrixForm


-119250, -96272.3, 99360.9 -101295, -101074, 81934.5 -78703.3, -91442, 62798.3 -4002.85, -15345.5, 3604.86 -29904, -42238, 23428.3 49070, 29595.8, -33869.8

I would need to input this values at Wk1 {X,Y,Z} into this first equation. Initial location Q0={0,0,0}, Q1 will have the new calculated position in {X1,Y1,Z1}

Q1= Q0 +Wk1*Δt (Equation 1)

Q2= Q1 +Wk2*Δt (Equation 2)

Qn= Qn-1 +WknΔt (Equation n, n=ndata points)


Δt=1/200 constant variable

Are there any short function that I can create an iteration function calculate all 433 ndata points, based on the raw data input or do I have to break down {x,y,z} into an individual matrix: {x}, {y} and {z} to perform the iteration function.

Appreciate your advice. Thank you.

JL.

• applying MatrixForm to Data1 is likely a problem (Though you never use Data1 in the remainder of the question..). Do Data1=Table[...] ; MatrixForm[Data1] Commented Mar 21, 2017 at 18:17

## 1 Answer

Just as example define:

rawdata = RandomReal[1, {100, 3}];


Then you can write it recursively as:

func[data_, 1] := G0 + dt WK[data[[1, 1]], data[[1, 2]], data[[1, 3]]];
func[data_, n_] :=
func[data, n - 1] + dt WK[data[[n - 1, 1]], data[[n - 1, 2]], data[[n - 1, 3]]]


Giving:

func[rawdata, 3]


G0 + dt WK[0.803669, 0.697727, 0.677939] + 2 dt WK[0.977735, 0.53124, 0.76784]

• Thank you Fabian. I will give it a try.
– ljsg
Commented Mar 22, 2017 at 8:08
• Hi Fabian I have try it using your method. However, the iteration did follow the exact method. Here is my code: In[692]:= func[ndata, 1] = 0 + DIMU1X[[1]]*Deltatime // N Out[692]= {-0.59625} In[694]:= func[ndata, 2] = func[ndata, 1] + DIMU1X[[2]]*Deltatime // N Out[694]= {-1.10273} In[695]:= CheckingTheta2 = Theta1 + DIMU1X[[2]]*Deltatime // N Out[695]= {-1.10273} In[699]:= func[ndata, i] = Table[func[[ndata - 1, i]] + DIMU1X[[i]]*Deltatime, {i, ndata}]; Thank you.
– ljsg
Commented Mar 22, 2017 at 9:52
• +1 for mind-reading :-) Commented Jun 20, 2017 at 10:37