Mathematica Asked by amator2357 on May 1, 2021
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.
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]}} *)
Correct answer by Bob Hanlon on May 1, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP