Group Abstract Group Abstract

Message Boards Message Boards

1
|
2.8K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Generating lists where new elements depend on the previous element

Posted 1 year ago
POSTED BY: Byron Alexander
2 Replies
Posted 1 year ago

You can use NestList or FoldList for this purpose in Mathematica. Here's a basic outline:

listOfTriplets = {{a1, b1, c1}, {a2, b2, c2}, ...};
f[{a_, b_, c_}, previousValue_] := (* Your function here *);

initialValue = (* Your initial value *);

result = FoldList[f, initialValue, listOfTriplets];

This way, FoldList will handle the dependency on the previous value efficiently.

POSTED BY: Zohaib Arshad
Posted 1 year 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