I want to add 19 lists together and then average over them but they are of unequal length. How do I make then all the same length? i.e. make them all the length of the smallest one.
My lists are called
nthrealisation[n_] := RESULTS[[{n}, All]];
For each n
(ranging from 1-19) the lists are different lengths.
RESULTS = {};
For[iterator = 1, iterator < 20, iterator++,
n = 200; m = 200; t = 0;
results = {{t, n, m}};
mu = 0.1; nimmig = 1;
While[t < 1000,
death = mu*2*n*m;
birth = mu*(n + m);
rate = death + birth + nimmig;
deltaT[r_] := -1/r*Log[RandomReal[]];
t1 = deltaT[rate];
t = t + t1;
rand = RandomReal[]*rate;
rand1 = RandomReal[];
rand2 = RandomReal[]*rate;
rand3 = RandomReal[];
Which[
rand <= death,
Which[
rand1 <= (n/(n + m)), (n = n - 1) && (m = m),
If[
(rand2 > death) && (rand2 <=death + birth) && (rand3 < (m/(n + m))), (n= n) && (m = m + 1), (n = n) && (m = m)
];
True, (n = n) && (m = m - 1)
If[
(rand2 > death) && (rand2 <=death + birth) && (rand3 < (n/(n + m))),(n = n + 1) && (m = m), (n = n) && (m = m)
];
];
(rand > death) && (rand <= death + birth),
Which[
rand1 < (n/(n + m)), (n = n + 1) && (m = m),
If[
(rand2 < death) && (rand3 < (m/(n + m))), (n = n) && (m =m - 1), (n =n) && (m = m)
];
True, (n = n) && (m = m + 1)
If[
(rand2 < death) && (rand3 < (n/(n + m))), (n = n - 1) && (m = m), (n= n) && (m = m)
];
];
True,
If[
rand1 <= 1/2, (n = n + 1) && (m = m), (n = n) && (m = m + 1)
];
];
results = Append[results, {t, n, m}];
];
AppendTo[RESULTS, results];
]
nthrealisation[n_] := RESULTS[[{n}, All]];
lists = Table[nthrealisation[n], {n, 19}]; With[{nmin = Min[Length /@ lists]}, Take[#, nmin] & /@ lists]
$\endgroup$Total[]
on the result of that last snippet, instead ofSum[]
. $\endgroup$Total[%]
in a new cell and evaluate that. $\endgroup$