# How to use the variables from Table in calculation

New to the site and Mathematica. I'm trying to use the finite element method to get a temperature profile. So if $q_0=f(T_0,T_1)$, $q_n=f(T_{n-1},T_n)$ and we also know that $T_1-T_0=T_2-T_1=T_3-T_2=\dotso=T_n-T_{n-1}$ We can solve for the $T_i$s. I know there is a way one can create the desired amount of variables by using Table[Subscript[T, n], {n, 0, 999}], but how to use them in the equations? I guess what I'm saying is how to solve a large amount of equations. Let me know if my question is not clear enough, I'll try to explain everything I know.

temp[Conc_, Kcond_, x_, h_] :=
NSolve[Qrad[Conc] == sigma*T0^4 + Qcond[Kcond, x, T0, T1] &&
Qcond[Kcond, x, T19, T20] == sigma*T20^4 + Qconv[h, T20] &&
Qcond[Kcond, x, T0, T1] == Qcond[Kcond, x, T1, T2] &&
Qcond[Kcond, x, T1, T2] == Qcond[Kcond, x, T2, T3] &&
Qcond[Kcond, x, T2, T3] == Qcond[Kcond, x, T3, T4] &&
Qcond[Kcond, x, T3, T4] == Qcond[Kcond, x, T4, T5] &&
Qcond[Kcond, x, T4, T5] == Qcond[Kcond, x, T5, T6] &&
Qcond[Kcond, x, T5, T6] == Qcond[Kcond, x, T6, T7] &&
Qcond[Kcond, x, T6, T7] == Qcond[Kcond, x, T7, T8] &&
Qcond[Kcond, x, T7, T8] == Qcond[Kcond, x, T8, T9] &&
Qcond[Kcond, x, T8, T9] == Qcond[Kcond, x, T9, T10] &&
Qcond[Kcond, x, T9, T10] == Qcond[Kcond, x, T10, T11] &&
Qcond[Kcond, x, T10, T11] == Qcond[Kcond, x, T11, T12] &&
Qcond[Kcond, x, T11, T12] == Qcond[Kcond, x, T13, T14] &&
Qcond[Kcond, x, T13, T14] == Qcond[Kcond, x, T14, T15] &&
Qcond[Kcond, x, T14, T15] == Qcond[Kcond, x, T15, T16] &&
Qcond[Kcond, x, T15, T16] == Qcond[Kcond, x, T16, T17] &&
Qcond[Kcond, x, T16, T17] == Qcond[Kcond, x, T17, T18] &&
Qcond[Kcond, x, T17, T18] == Qcond[Kcond, x, T18, T19] &&
Qcond[Kcond, x, T18, T19] == Qcond[Kcond, x, T19, T20] && T0 > 0 &&
T1 > 0 && T2 > 0 && T3 > 0 && T4 > 0 && T5 > 0 && T6 > 0 &&
T7 > 0 && T8 > 0 && T9 > 0 && T10 > 0 && T11 > 0 && T12 > 0 &&
T13 > 0 && T14 > 0 && T15 > 0 && T16 > 0 && T17 > 0 && T18 > 0 &&
T19 > 0 && T20 > 0, {T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,
T11, T12, T13, T14, T15, T16, T17, T18, T19, T20}]
temp[3, 12, 0.01, 250]


Basically this is what I want but instead of typing them all out(which I can't) I was wondering if there is a way to simplify this. Thanks!

• It might help if you specify the equations you want to use. As opposed to asking how to use variables in equations. Additionally, the documentation for Solve and Reduce describe how to solve system of equations in Mathematica. – IPoiler Oct 2 '15 at 3:00
• thanks. I think my problem is not how to solve them but how to define the variables in a simpler way. I just can't find any examples for that and since I don't have any programming experience this got me a lot of trouble. – Fang Oct 2 '15 at 3:20
• Your equations seem identical except at the first and last time steps, so why not use Table again to generate the equations? The inequalities for example can be generated by Table[ic>0,{ic,list}] when list=Table[Subscript[T, n], {n, 0, 999}]. – IPoiler Oct 2 '15 at 3:29
• ...Although I don't recommend using Subscripts. I would use T[n] instead. – march Oct 2 '15 at 3:31

temp[Conc_, Kcond_, x_, h_] := NSolve[
And @@ Join[
{Qrad[Conc] == sigmaT0^4 + Qcond[Kcond, x, T[0], T[1]], Qcond[Kcond, x, T[19], T[20]] == sigmaT20^4 + Qconv[h, T[20]]}
, Array[Qcond[Kcond, x, T[#], T[# + 1]] == Qcond[Kcond, x, T[# + 1], T[# + 2]] &, 19, 0]
, T[#] > 0 & /@ Range[0, 20]
]
, Table[T[k], {k, 0, 20}]
]


There are a couple of different ways to create lists automated lists of the type you're looking for. Embedded in the code above are some examples. The most straightforward is the last:

Table[T[k], {k, 0, 20}]
(* {T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9], T[10], T[11], T[12], T[13], T[14], T[15], T[16], T[17], T[18], T[19], T[20]} *)


Two others involve Array (look it up in the documentation) and Map (/@) (look it up in the documentation. In addition, I am using pure functions. For instance, T[#] > 0 &. This is shorthand for

Function[{x}, T[x] > 0]


and it is an object that when you attach [a] to it, it puts a in the spot of # (x):

T[#] > 0 & [a]
Function[{x}, T[x] > 0][a]
(* T[a] > 0 *)
(* T[a] > 0 *)


Take this example and run with it.

• Thanks so much for the help. There are a lot of command that I've never seen before so I guess it will take a bit time to understand. But this definitely seems enlightening. – Fang Oct 2 '15 at 3:58

As march pointed out in the comment it would be better to use Array. Then you can define a function like

   f[i_] := Qcond[Kcond, x, T[i], T[i + 1]] ==
Qcond[Kcond, x, T[i + 1], T[i + 2]]


Use Thread to write the conditional part 1

  c1[n_] := And @@ Thread[Array[f, n, 0]]


For the remaining part again use Thread

  c2[n_] := And @@ Thread[Array[T, n, 0] > 0]


   var = Table[T[i], {i, 1, 20}]

 temp[Conc_, Kcond_, x_, h_] :=