0
$\begingroup$

My intention with the following code:

step = 0.1;
time = Table[i, {i, 0, 100, step}];
T = Table[0, {i, Length[time]}];
tt = Prepend[T, 90];

temp = 0;
Do[
 tr = tt[[i]]+temp;
 temp = ((tr + 273.15) - time[[i+1]]) - 273.15
   // Print, {i, 1, 100, 1}
 ]

is to have tr to be updated each time as if you were reading it line by line. In other words, to have tr to be in the first iteration 90, and then in the following iterations whatever the value of temp is in each iteration. As an example, for the first iteration temp should be temp = ((90 + 273.15) - 0.1) - 273.15 =89.9. In the second iteration temp should be temp = ((89.9 + 273.15) - 0.2) - 273.15 =89.7. In the third iteration temp should be temp = ((89.7 + 273.15) - 0.3) - 273.15 =89.4 and so on. I am do not think the do loop is the appropiate loop for this but I am not what would be the best strategy for this. I appreciate your inputs in advanced

$\endgroup$
  • $\begingroup$ having hard time figuring what you want. Is it {89.9, 89.7, 89.4, 89., 88.5, 87.9, 87.2, 86.4, 85.5, 84.5,etc....} or something else? Answer below gives the above. May be you can give a small explicit example (say i=1..3 only and show what list should the loop generate. This is easier than describing with words. $\endgroup$ – Nasser Apr 29 at 18:51
  • $\begingroup$ @ Nasser What I want is is to compute temp=((tr + 273.15) - time[[i+1]]) - 273.15 by using updating tr each time. So that in the first iteration tr=90, in the second tr=temp, in the third tr=temp and so on. So I want 'tr' to be 90 at first by then to get the value of temp after the second iteration. I hope that helps clarify it $\endgroup$ – John Apr 29 at 19:05
  • $\begingroup$ But this is what the answer below gives. Again, it will much simpler to give the ACTUAL list you want to see for say {i, 1, 3 1} instead of using words to describe things. This will make things much more clear. $\endgroup$ – Nasser Apr 29 at 19:15
  • $\begingroup$ @Nassar Yes, that's what the code below does but it is not the same to get an answer than to compute it, right?. I just would like to perform the loop or in a line were temp is compute it (which the other code happens to get the answer to but it does not compute temp) $\endgroup$ – John Apr 29 at 19:40
  • $\begingroup$ for i=i temp will generate 89.9, for i=2 temp will generate 89.7, for i=3 temp will generate 89.4. It would do so by having 'tr' to be 90 for i=i tr=temp for any iteration after that. $\endgroup$ – John Apr 29 at 19:51
2
$\begingroup$

So, something like

FoldList[Plus, 90, -Table[i/10.0, {i, 1, 25}]]

might suit your needs ?

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you for your answer. However, even though your code gets the answer I need it is not using time and not getting the computation for temp. I would like to get temp if I were to change 'time' for some other values for instance.I would be great if that can be accomplish by getting tr updated each time $\endgroup$ – John Apr 29 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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