I have a function F[i_Integer,B_List,l_list]
which spits out a list {B',l'}
where B'
and l'
are of the same dimension as B
and l
, respectively. Now I want to get F[j,B',l']
and I then want to use the output of that again to get F[k,B'',l'']
, etc. (note that the integer argument changes at each step). What is the best way to do this? I'd be grateful for any help.
$\begingroup$
$\endgroup$
1
1 Answer
$\begingroup$
$\endgroup$
1
F[i_Integer, B_List, l_List] := {B - i, l + i}
B = Array[b, 3]; l = Array[L, 4];
SeedRandom[123]; {i, j, k} = RandomInteger[{-5, 5}, 3]
(* {2, -1, 5} *)
Fold[F[#2, Sequence @@ #1] &, {B, l}, {i, j, k}]
(* {{-6 + b[1], -6 + b[2], -6 + b[3]}, {6 + L[1], 6 + L[2], 6 + L[3],
6 + L[4]}} *)
F[{B_List,l_List},i_Integer]
and then doFold[F,{B,l},{i,j,k}]
but is defining a function which takes as an argument a list of lists a bad practice? $\endgroup$