Message Boards Message Boards

1
|
8070 Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

How to realize the function Nest[] with two replaced variables?

Posted 6 years ago

How to realize Nest[{a,b,#1,#2} &, ]? For example, #1 should be replaced by x, and #2 by y simultaneously or even respectively ?

POSTED BY: Math Logic
5 Replies
Posted 6 years ago
POSTED BY: Math Logic

I do this frequently. The easy way is to define a function that deconstructs a single composite argument with a pattern:

f[{a_, b_}] := {a + 1, b + a}
Nest[f, {0, 0}, 10]
(* {10, 45} *)

If I'm feeling fussy, I'll use a custom wrapper symbol rather than List:

f[state[a_, b_]] :=state[ a + 1, b + a]
Nest[f, state[0, 0], 10]
(* state[10, 45] *)
POSTED BY: John Doty
Posted 6 years ago

So smart! Thank you !!

POSTED BY: Math Logic
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