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'm developing a model of thermodynamic cycle in Mathematica. I wrote several functions, applied them to a list containing starting values and iterated, for the model to converge.

fixed = FixedPoint[
  f1[f2[Nest[f3,f4[f5[f6[Nest[f7, f8[#], 100]]]],100]]] &, startinglist, 20];

I would like to see not only final, converged values, but also values at each other point of the cycle, so I threw them into a grid:

data = {
  Prepend[fixed, "starting point"],
  Prepend[f8[fixed], "before condenser"],
  Prepend[Nest[f7, f8[fixed], 100], "after condenser"],
  Prepend[f6[Nest[f7, f8[fixed], 100]], "before pump"],
  Prepend[f5[f6[Nest[f7, f8[fixed], 100]]], "after pump"],
  Prepend[f4[f5[f6[Nest[f7, f8[fixed], 100]]]], "before heat exch"], 
  Prepend[Nest[f3, f4[f5[f6[Nest[f7, f8[fixed], 100]]]], 100], "after heat exch"],
  Prepend[f2[Nest[f3,f4[f5[f6[Nest[f7, f8[fixed], 100]]]], 100]],"before turbine"],
  Prepend[f1[f2[Nest[f3,f4[f5[f6[Nest[f7, f8[fixed], 100]]]], 100]]], "after turbine"]
};

Text@Grid[
  Prepend[data, {"Point", "Temp [\[Degree]C]", "pressure [bar]", "enthalpy [kJ/kg]", 
  "enthropy [kJ\kg\K]", "density [kg/m3]", "viscosity [kg/m/s]", "quality [-]"}], 
 Frame -> All]

It works, but doesn't look very clean. The second thing is that while creating data Mathematica is once again performing Nest, which might consume a lot of time, if I'm going to extend my model. Any other ways to do all of that quicker?

share|improve this question
    
Related (to implicit title q.): mathematica.stackexchange.com/questions/10163/… –  Michael E2 Nov 8 '13 at 13:47
add comment

1 Answer

up vote 1 down vote accepted

Perhaps something like:

(* Setup sample functions *)
f1 = f2 = f3 = f4 = f5 = f6 = f7 = Identity;
f8[x_] = -x; 

h = FixedPoint[f1[g = f2[f = Nest[f3, e = f4[d = f5[c = f6[b = Nest[f7, a = f8[#], 100]]]], 
              100]]] &, {1}, 20];
data =
 {{"starting point", h},
  {"before condenser", a}, .. etc.}
share|improve this answer
    
Something like that worked, thanks! –  Wojciech Nov 13 '13 at 8:02
add comment

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.