Clear["`*"]; v = 1; t = 18; dt = 0.005; n = t/dt; T = {{{0, 10}}, {{10, 10}}, {{10, 0}}, {{0, 0}}}; For[j = 1, j <= n, j++, For[i = 1, i <= 4, i++, x1 = T[[i, j, 1]]; y1 = T[[i, j, 2]]; If[i != 4, x2 = T[[i + 1, j, 1]]; y2 = T[[i + 1, j, 2]], x2 = T[[1, j, 1]]; y2 = T[[1, j, 2]] ]; x1 = x1 + (v dt (x2 - x1))/Sqrt[(x2 - x1)^2 + (y2 - y1)^2]; y1 = y1 + (v dt (y2 - y1))/Sqrt[(x2 - x1)^2 + (y2 - y1)^2]; T[[i]] = Append[T[[i]], {x1, y1}] ] ]; Graphics[{Line[T], Line[{{0, 10}, {10, 10}, {10, 0}, {0, 0}, {0, 10}}]}]
This code for solving MiceProblem in the procedural style, is it possible implement by functional style? Table
or Nest
may required. I only can replace For
with Do
.