5
$\begingroup$

I would like to generate a code which emulate the calculations that are being perfom in columns A and B and row 7 to 12 in the attached first image. The results of those calculations are those shown in the second image. Please notice that "0" and "50" in Colum A and B and row 6 are simply the initial values to perform the calculations.

I am not interested in importing the values but rather generate a code which does the same and where I can obtain column A and B (including 0 and 50) as lists. Thank you very much in advanced,

Edit: I would appreciate if the code could be general (such as a loop) as in the case if there more rows. Also it is only neccesary to generate a list column A and B only from row 5 on.

Image 1

Image 2

$\endgroup$
  • $\begingroup$ In a better world, someone could add a TableView-based solution here :) $\endgroup$ – user5601 Apr 29 at 23:58
3
$\begingroup$

Is this close enough?

TableForm[
{{"step",b1=0.001},
{"p",b2=1000},
{" "," "},
{"Time(s)", "T[C]"},
{a6=0,b6=50},
{a7=a6+b1,b7=((b6+273.15)-b2*a7)-273.15},
{a8=a7+b1,b8=((b7+273.15)-b2*a8)-273.15},
{a9=a8+b1,b9=((b8+273.15)-b2*a9)-273.15},
{a10=a9+b1,b10=((b9+273.15)-b2*a10)-273.15},
{a11=a10+b1,b11=((b10+273.15)-b2*a11)-273.15},
{a12=a11+b1,b12=((b11+273.15)-b2*a12)-273.15}}]

or this

TableForm[Join[{{"step",b[1]=0.001},
{"p",b[2]=1000},
{" "," "},
{"Time(s)", "T[C]"},
{a[6]=0,b[6]=50}},
Table[{a[i]=a[i-1]+b[1],b[i]=((b[i-1]+273.15)-b[2]*a[i])-273.15},{i,7,20}]]]

but I suspect that you can easily keep adding more requirements or writing more complicated cross referencing formulas in your spread sheet to break any answer.

| improve this answer | |
$\endgroup$
  • $\begingroup$ thank you very much. It is. But do you know how to make it more general like in a loop or something?. In other words, if I had more than 12 rows then it will be difficult to write down every formula for each row. I would appreciate if you can help me with this! $\endgroup$ – John Apr 29 at 20:48
  • $\begingroup$ your code is great and it works excelent for my purposes! I really appreaciate your help. $\endgroup$ – John Apr 29 at 21:03
6
$\begingroup$

This is simply a translation of the recursive rules indicated:

Block[
  {step = 0.001, p = 1000},
  NestList[
    Apply[{#1 + step, ((#2 + 273.15) - p*(#1 + step)) - 273.15} &], 
    {0, 50}, 
    6
  ]
]

(* Out:
{{0, 50}, {0.001, 49.}, {0.002, 47.}, {0.003, 44.}, 
 {0.004, 40.}, {0.005, 35.}, {0.006, 29.}}
*)
| improve this answer | |
$\endgroup$
  • $\begingroup$ this code is great and it also works excelent for my purposes! I really appreaciate your help as well. I am glad that now I have two ways of doing it ! $\endgroup$ – John Apr 29 at 21:04
  • $\begingroup$ @John Glad it helped! $\endgroup$ – MarcoB Apr 29 at 21:05

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.