I have matrix and and i want to do increment in a do loop and and i want to store in list using append to. It works fine for less values, But when i want to do it for values around 1 million the program is slow.
x = {{0.1},{0.2}};xm = {{0.4},{0.5}}; Do[datax[i] = {}; dataxm[i] = {};, {i, 1, 2}] Do[ x = x + t; xm = xm + t; Do[AppendTo[datax[i], Flatten[{t, x[[i]]}]];, {i, 1, 2}]; Do[AppendTo[dataxm[i], Flatten[{t, xm[[i]]}]];, {i, 1, 2}], {t, 0, 1, 0.1}] datax[1] {{0., 0.1}, {0.1, 0.2}, {0.2, 0.4}, {0.3, 0.7}, {0.4, 1.1}, {0.5, 1.6}, {0.6, 2.2}, {0.7, 2.9}, {0.8, 3.7}, {0.9, 4.6}, {1., 5.6}} datax[2] {{0., 0.2}, {0.1, 0.3}, {0.2, 0.5}, {0.3, 0.8}, {0.4, 1.2}, {0.5, 1.7}, {0.6, 2.3}, {0.7, 3.}, {0.8, 3.8}, {0.9, 4.7}, {1., 5.7}} dataxm[1] {{0., 0.4}, {0.1, 0.5}, {0.2, 0.7}, {0.3, 1.}, {0.4, 1.4}, {0.5, 1.9}, {0.6, 2.5}, {0.7, 3.2}, {0.8, 4.}, {0.9, 4.9}, {1., 5.9}} dataxm[2] {{0., 0.5}, {0.1, 0.6}, {0.2, 0.8}, {0.3, 1.1}, {0.4, 1.5}, {0.5, 2.}, {0.6, 2.6}, {0.7, 3.3}, {0.8, 4.1}, {0.9, 5.}, {1., 6.}} Similar to the above I want to use reap and sow functions to speed it up but i can store only the last value. Why?
x = {{0.1},{0.2}};xm = {{0.4},{0.5}}; Do[ x = x + t;xm = xm + t; Do[datax[i] = Reap[Sow[{t, x[[i]]}]][[2, 1]], {i, 1, 2}]; Do[dataxm[i] = Reap[Sow[{t, xm[[i]]}]][[2, 1]], {i, 1, 2}]; , {t, 0, 1, 0.1}] datax[1] {{1., {5.6}}} datax[2] {{1., {5.7}}} datax[1] {{1., {5.9}}} datax[2] {{1., {6.0}} Can anyone help in fixing this issue? Thanks in advance