Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to carry out a following iteration process:
Apply function f1[a_,b_,c_,d_] to a starting list l1={a1,b1,c1,d1}, which will result in l2={a2,b2,c2,d2}. Then apply function f2[a_,b_,c_,d_] to list l2 to get l3={a3,b3,c3,d3}. Finally apply function f3[a_,b_,c_,d_] to list l3 to get l4={a4,b4,c4,d4}. As soon as this is over, I would like {a4,b4,c4,d4} to be the starting values of the process, in other words to start the procedure with values of l4 obtained in the previous step. This should repeat until l1 and l4 in the same step are identical. It would be also good if I could get lists l1,...,l4 from the last step returned at the end of the process. Any idea how can I do it in Mathematica?

I couldn't find a similar problem solved on the net. I read all about FixedPoint, NestWhile and Fold in the documentation, but I still don't know how to apply it to this problem, so I'd be grateful for all tips and advices.

Functions f1,...,f3 are a bit complicated and involve reading values from dll library. Let's say they look like this one:

f1[{a_,b_,c_,d_}]:={
  afrombc[b-0.2,c],
  b-0.2,
  c,
  dfromab[afrombc[b-0.2,c],b-0.2]
}

afrombc[] and dfromab[] are predefined functions connected with dll library.

share|improve this question
    
Please format your question (see the format help) and supply (dummy) input, output and functions to show what you want to do. –  Yves Klett Oct 29 '13 at 12:52
    
Sounds like a plain FixedPoint application. In what way does FixedPoint[f3[f2[f1[#]]] &, {a1, a2, a3, a4}] or similar does not work for you? –  Yves Klett Oct 29 '13 at 13:44
    
Input is a problem in this case, even if it is supposed to be a dummy one. FixedPoint[f3[f2[f1[#]]] &, {a1, a2, a3, a4}] would mean that the iteration goes until {a1, a2, a3, a4} doesn't change in two subsequent steps? –  Wojciech Oct 29 '13 at 13:47
    
But as long as your function (or chain of functions, which acts as one) converge, in principle the FixedPoint approach should work, right? Anything more specific will depend on you supplying working functions. –  Yves Klett Oct 29 '13 at 13:50
    
You're right, in principle it should work. I need some time to play with it. I'll let You know as soon as I have something, but thanks for Your help so far. –  Wojciech Oct 29 '13 at 13:57

1 Answer 1

up vote 4 down vote accepted

This calls for FixedPoint. I add Composition and pure functions for enhanced value (in case you have many functions and want to chain them conveniently). The dummy functions here are ultimate simpletons, but the principle works as long as inputs and outputs for the functions are compatible:

{f1, f2, f3} = {#^(1/2) &, #^(1/3) &, #^(1/4) &};

FixedPoint[Composition[f3, f2, f1][#] &, .1]
1.

Equivalent function calls would be:

FixedPoint[f3@f2@f1[#] &, .1] 

or

FixedPoint[f3[f2[f1[#]]] &, .1]

Works also with lists in this case:

FixedPoint[Composition[f3, f2, f1][#] &, {0.1, .9, 1, 1.5}]

{1., 1., 1, 1.}

but here for exact numbers other than 1, you will be in trouble and you might want to use the third argument to FixedPoint, which defines the max. number of iterations:

FixedPoint[f3[f2[f1[#]]] &, 2, 20]
2^(1/4019988717840603673710821376)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.