Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.3K Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Define a recursive sequence

Posted 5 years ago

Hi, I am quite new in Mathematica and I have a problem I am not able to solve for some time. I need to calculate a thermodynamical problem, where I have heat transfer within the annulus of two pipes. To calculate the temperature difference between the two pipes I need to do a recursive sequence. The following code is just a very simplified one.

dT = 0.5;
Tinside = 25;

R[dT_] = (2*dT*3)/5;

Nu[dT_] = (R[dT]*2)/(R[dT]*6);

hb[dT_] = (5*Nu[dT])/6;

hr[dT_] = (5 - dT)*(4 - dT);

Res[dT_] = 1/(2*hb[dT]) + 1/(2*hr[dT]);

Toutside[dT_] = 6/Res[dT]/(2/(4*Res[dT]));

dTnew[dT_] = Tinside - Toutside[dT];

DeltaT = NestList[{R[dT], Nu[dT], hb[dT], hr[dT], Res[dT], Toutside[dT], 
   dTnew[dT]}, dT, 2]

The output of 2 recursive steps of this Calculation is: {0.5, {0.6, 0.333333, 0.277778, 15.75, 1.83175, 12., 13.}[ 0.5], {0.6, 0.333333, 0.277778, 15.75, 1.83175, 12., 13.}[{0.6, 0.333333, 0.277778, 15.75, 1.83175, 12., 13.}[0.5]]}

What i want Mathematica to do, is to redefine dTnew as my new dT an recalculate the whole process many more times, to become an accurate temperature difference (dTnew) after about 10 recursive steps. At the very beginning i just defined my dT=0.5 as a "starting point". Is it possible to do this with NestList, or is there another, maybe more efficient way? Any help would be appreciated! Thank you in advance!

POSTED BY: Thomas Robinson
6 Replies

Ok, I will try again:

The only way i figured out so far is to insert my R in Nu, insert Nu in hb, hb in hr, hr in Res, Res in Toutside and Toutside in dTnew . ...

No! You do not have to insert one function into another, you just make clean definitions of your single functions and finally invoke dTnew - there is no "mess" at all! This works, because dTnew calls Toutside, Toutside calls Res, and so on, and all these functions are by then known to the system.

dTnew should have a single number as variable (i.e. as input) and should give back a single number as output. You should first check whether dTnew gives a meaningful output at all - at the moment it probably does not!

Then

deltaT = NestList[dTnew, 0.5, 10]

will give a list of the stepwise evolution of your values, starting from dT=0.5

Or am a entirely misunderstanding you problem? Regards -- Henrik

POSTED BY: Henrik Schachner
Posted 5 years ago

Oh Thanks, right now it just works fine. Thank you so much for your help!

POSTED BY: Updating Name

Hello Thomas,

with a clean function definition dTnew[dT_]:= ... you get the list of iterations like so:

evol = NestList[dTnew, dT, 5]

and e.g. the pairwise difference of these steps:

Differences[evol]

Clean function definitions would read:

R[dT_] := (2*dT*3)/5;
Nu[dT_] := (R[dT]*2)/(R[dT]*6);
hb[dT_] := (5*Nu[dT])/6;
hr[dT_] := (5 - dT)*(4 - dT);
Res[dT_] := 1/(2*hb[dT]) + 1/(2*hr[dT]);
Toutside[dT_] := 6/Res[dT]/(2/(4*Res[dT]));
dTnew[dT_] := Tinside - Toutside[dT];

But with these definitions the function dTnew[dT_] always evalutates to 13 - I guess this is not what you want:

Tinside = 25;
dTnew[whatever]
(*  Out:  13  *)
POSTED BY: Henrik Schachner

Hi Henrik! Thank you so much for your reply! Actually the inside Temperatur Tinside is given and R, Nu, hb, hr, Res are dependent of dT and act like or are part of Resistors. Toutside is the temperature of the outer Pipe, hence dTnew is my new Temperature difference between my pipe outside and inside. To become my true temperature differences, i want to iterate through R, Nu, hb, hr, Res , Toutside and dTnew over and over again. So at the very beginning i set my assumed temperature difference of the annulus dT=0.5. as my dTnew is calculated, i want to set my dTnew as my new dT to run through R, Nu, hb, hr, Res, Toutside and dTnew again. By this i want to become my final value (after lets say 10 steps) of my true temperature differnce within the annulus. If there are any questions left, please let me know. Thank you so much for your help! I appreciate it!

POSTED BY: Thomas Robinson

Yes, yes, I guess I had understood all that. But my point is that with these definitions your function dTnew evaluates to some constant (namely 13) - all dependency on its argument has canceled out. Iterating a constant function does probably not make much sense,

POSTED BY: Henrik Schachner

Ok! I wasn´t sure of how to do this, i just read through some possibilites, but until now i still don´t know of how to solve this problem. Is there a simple way of merging these function an iterate my dTnew?

The only way i figured out so far is to insert my R in Nu, insert Nu in hb, hb in hr, hr in Res, Res in Toutside and Toutside in dTnew . After i have done this i can iterate via final

DeltaT = NestList[dTnew, 0.5, 10]

But my original code is quite long and doing this that way it becomes a mess and the overview of my calculations is not given anymore.I also need an interim result, for another calculation. I hope it is clear of what i am trying to do. Actually i am not even sure if this is possible with a NestList-function. Is there a way? Thank you so much!

POSTED BY: Thomas Robinson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard