Message Boards Message Boards

1
|
308 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

Generating lists where new elements depend on the previous element

Posted 1 month ago

Hi all, I am interested in using some type of list or table in-built Mathematica function to generate a list, where the elements of the new list not only depends on the input values of a previously defined list of triplets which I denote as 'a', but also depends on the output value of the previous element of the new list. In this sense I will provide the list of triplets, the function f which takes the triplets as inputs, and the first element of the new list. Then the list should generate itself.

I provide a simple example, not the actual problem, where I use the % symbol in Mathematica to assign the previous cell output to the next iteration. But of course this is not efficient for long triplet lists. Can anyone advise on a more efficient way of doing this type of problem? Many thanks.

POSTED BY: Byron Alexander
Posted 1 month ago

May be something like this?

FoldList[#1 f[x, Sequence @@ #2] &, Cos[x], a]

{Cos[x], Cos[x] Sin[x], Cos[x] Sin[x]^2, Cos[x] Sin[x]^3, 
 Cos[x]^2 Sin[x]^3, x Cos[x]^2 Sin[x]^3}

FoldList
Sequence

POSTED BY: Denis Ivanov
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