2

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?

Wojciech
  • 398
  • 4
  • 15
  • Related (to implicit title q.): http://mathematica.stackexchange.com/questions/10163/how-to-span-table-headings – Michael E2 Nov 08 '13 at 13:47

1 Answers1

1

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.}
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453