I have a very large table in Mathematica ((dimcub-1)^3 elements) coming from an inverse FFT. I need to use periodic interpolation on this table. Since periodic interpolation requires that the first elements and last elements are equal, I create a new table of dim^3 elements manually and use that in my interpolation. It works but it is ugly/slow and due to my superfluous intermediate table, I hit the memory barrier sooner. Can any one tell me either how to turn my old table into a periodic one somehow by appending elements or use my non periodic table to make a periodic interpolation function? Here is my current piece of code:
mr 1 is the new table:
mr1 = Table[ 0. , {i, 1, dimcub}, {j, 1, dimcub}, {k, 1, dimcub}];
Do[Do[ Do[
mr1[[m, n, k]] = oldtable[[m, n, k]] ; , {m, 1,
dimcub - 1}]; , {n, 1, dimcub - 1}]; , {k, 1, dimcub - 1}];
Do[Do[ mr1[[m, n, dimcub]] = mr1[[m, n, 1]];
mr1[[m, dimcub, n]] = mr1[[m, 1, n]];
mr1[[dimcub, m, n]] = mr1[[1, m, n]]; , {m, 1, dimcub - 1}];
mr1[[n, dimcub, dimcub]] = mr1[[n, 1, 1]];
mr1[[dimcub, n, dimcub]] = mr1[[1, n, 1]];
mr1[[dimcub, dimcub, n]] = mr1[[1, 1, n]]; , {n, 1, dimcub - 1}];
mr1[[dimcub, dimcub, dimcub]] = mr1[[1, 1, 1]];
Remove[oldtable];
myinterpolatingfunction =
ListInterpolation[mr1, {{1, dimcub}, {1, dimcub}, {1, dimcub}},
InterpolationOrder -> 1,
PeriodicInterpolation -> True];
Remove[mr1];
myinterpolatingfunction takes much less memory and works perfectly once i remove the older tables. Any help will be greatly appreciated.
Thanks for all the answers. I tried the suggestion by leonid but when I print my oldtable, it was still (dimcub -1)^3 dimensional. New elements were defined and I can see them individually but they do not show up as part of the oldtable when I print the whole table. So I ended up with something similar which is doing exactly what I needed:
The answer by Wizard is far too advanced for my level of mathematica..