Message Boards Message Boards

0
|
2564 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Loop computation or Store and reuse Output

Starting from a number N, I apply 4 simple Functions and I get 4 outputs A, B, C, D.

I would like to find a way to reapply the 4 Functions by replacing N -> A, B, C, D and get A1, B1, C1, D1 - A2, B2, C2, D2 - A3, B3, C3, D3 - A4, B4 , C4, D4

or save and archive in a separate list the results A, B, C, D obtained by manually replacing N with the values A, B, C, D.

Any ideas?

TNK's

POSTED BY: Mutatis Mutandis
3 Replies

You can use Outer:

functions = {f1, f2, f3, f4};
Outer[#1[#2[n]] &, functions, functions]
Outer[#1[#2[#3[n]]] &, functions, functions, functions]
POSTED BY: Gianluca Gorni

You can use NestList:

fourFunctions[{a_, b_, c_, d_}] := {f1[a], f2[b], f3[c], f4[d]};
start = {n, n, n, n};
NestList[fourFunctions, start, 3]
POSTED BY: Gianluca Gorni

• this is OUT:

    {{n, n, n, n},

    {f1[n], f2[n], f3[n], f4[n]},

    {f1[f1[n]], f2[f2[n]], f3[f3[n]], f4[f4[n]]},

    {f1[f1[f1[n]]], f2[f2[f2[n]]], f3[f3[f3[n]]], f4[f4[f4[n]]]}}

• at the 3rd step I want to get 16 outputs:

    {f1 [f1 [n]], f1 [f2 [n]], f1 [f3 [n]], f1 [f4 [n]]},

    {f2 [f1 [n]], f2 [f2 [n]], f2 [f3 [n]], f2 [f4 [n]]},

    {f3 [f1 [n]], f3 [f2 [n]], f3 [f3 [n]], f3 [f4 [n]]},

    {f4 [f1 [n]], f4 [f2 [n]], f4 [f3 [n]], f4 [f4 [n]]},

• and, at the 4th step, 64 outputs, if possible ...

POSTED BY: Mutatis Mutandis
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract