The following code is supposed generates a table based on different calculations for a given q
(e.g. q[1] for this example):
numberofrows = 40;
deltat = 0.00000001;
Tref = {353.15, 333.15};
nref = {0.830144995, 0.654953157};
kref = {1.541030575, 0.016538198};
Earef = {106310.1492, 261971.1364};
initialxt = 1*10^-12;
q = {0.1, 0.3, 1, 3, 10, 30, 100, 300, 600, 1000};
ttall = TableForm[
Join[{{"Delta t (s)", b[1] = deltat}, {"q (K/s)",
b[2] = q[[1]]}, {""}, {""}, {"Time(s)", "T[C]", "K(T)=k^(1/n)",
"dx/dT", "x(t)", "DH,aged-DH,unaged (J/g)",
"Check dx"}, {a[6] = 0, b[6] = 90.01,
c[6] = (kref[[1]]*
Exp[(-Earef[[1]]/
8.314)*((1/(90.01 + 273.15)) - (1/Tref[[1]]))])^(1/
nref[[1]]),
d[6] = (c[7]*
nref[[1]]*(1 -
initialxt)*(-Log[1 - initialxt])^((nref[[1]] - 1)/
nref[[1]]))/q[[1]], e[6] = (b[6] - b[7])*d[6] + initialxt,
f[6] = e[6]*90.01, g[6] = e[6]}},
Table[{a[i] = a[i - 1] + b[1],
b[i] = ((b[i - 1] + 273.15) - b[2]*a[i]) - 273.15,
c[i] = (kref[[1]]*
Exp[(-Earef[[1]]/
8.314)*((1/(b[i] + 273.15)) - (1/Tref[[1]]))])^(1/
nref[[1]]),
d[i] = (c[i + 1]*
nref[[1]]*(1 -
e[i - 1])*(-Log[1 - e[i - 1]])^((nref[[1]] - 1)/
nref[[1]]))/q[[1]],
e[i] = (b[i] - b[i + 1])*d[i] + e[i - 1], f[i] = e[i]*90.01,
g[i] = e[i] - e[i - 1]}, {i, 7, numberofrows - 9}]]]
What I want is to get a code where I can get the same table for the 10 different values of q
. I tried using a Do
loop putting different values of q
(e.g. q[[j]]) such as:
Do[
ttall = TableForm[
Join[{{"Delta t (s)", b[1] = deltat}, {"q (K/s)",
b[2] = q[[j]]}, {""}, {""}, {"Time(s)", "T[C]", "K(T)=k^(1/n)",
"dx/dT", "x(t)", "DH,aged-DH,unaged (J/g)",
"Check dx"}, {a[6] = 0, b[6] = 90.01,
c[6] = (kref[[1]]*
Exp[(-Earef[[1]]/
8.314)*((1/(90.01 + 273.15)) - (1/Tref[[1]]))])^(1/
nref[[1]]),
d[6] = (c[7]*
nref[[1]]*(1 -
initialxt)*(-Log[1 - initialxt])^((nref[[1]] - 1)/
nref[[1]]))/q[[j]],
e[6] = (b[6] - b[7])*d[6] + initialxt, f[6] = e[6]*90.01,
g[6] = e[6]}},
Table[{a[i] = a[i - 1] + b[1],
b[i] = ((b[i - 1] + 273.15) - b[2]*a[i]) - 273.15,
c[i] = (kref[[1]]*
Exp[(-Earef[[1]]/
8.314)*((1/(b[i] + 273.15)) - (1/Tref[[1]]))])^(1/
nref[[1]]),
d[i] = (c[i + 1]*
nref[[1]]*(1 -
e[i - 1])*(-Log[1 - e[i - 1]])^((nref[[1]] - 1)/
nref[[1]]))/q[[j]],
e[i] = (b[i] - b[i + 1])*d[i] + e[i - 1], f[i] = e[i]*90.01,
g[i] = e[i] - e[i - 1]}, {i, 7, numberofrows - 10}]]] //
Print, {j, 1, 10, 1}]
But it does not seem to work and I don't understand why or how to fix it. Edit: The problem with the Do
loop is that some of the values from the second table and on do not seem to be computing. The values which usually do not compute from table 2 and beyond are those from column 4,5,6,7 or in my notation d,e,f and g. This happens when numberofrows
is bigger than 21 for some reason. Here's a picture of how the second table (meaning q=0.3) look like for numberofrows=30
and when using the Do
loop:
Additionally, I notice that everytime I close the mathematica program and I open it again, for some reason I have to use instead of {i, 7,numberofrows - 9}
I have to change it to {i, 7,numberofrows - 10}
and then {i, 7,numberofrows - 11}
and so on. Is this a problem of using TableForm in the way I am doing it or why does this happen?
PS: This is a corrected and revised version than I previously asked question here: Problem with Do Loop and TableForm . I made sure it works and it is more clear now.
I will appreciate your comments
......g[i] = e[i] - e[i - 1]}, {i, 7, numberofrows - 9},{j, 1, 10}
and it does not work. I am not sure if that is the position where{j, 1, 10}
should go to make it work $\endgroup${i, 7,numberofrows - 9}
still explains the same problem with this new version. But also, the problem I mentioned is the reason why the table 2 has incorrect values ford
,e
,f
andg
. $\endgroup$d[i]
,e[i]
,f[i]
, andg[i]
in theTable
statement depends on undefined values forb[i+1]
andc[i+1]
. However, when table 2 is computed, theseb[i+1]
andc[i+1]
values are not undefined, because their values remain from table 1, so instead of using undefinedb[i+1]
andc[i+1]
for table 2, you use the values from table 1. You can solve that withDo[ Clear[a,b,c,d,e,f,g];
... Still, the last row will show undefined values (e.g.,b[31]
andc[31]
). $\endgroup$