doctorkan
neutrino
Offline
Posts: 2
|
 |
« on: August 14, 2010, 05:10:51 AM » |
|
CountingPaths[k_, n_, nn_, m_, opts___] := Module[{matrix, triangle, path}, matrix = {{Cos[a], Sin[a]}, {-Sin[a], Cos[a]}} /. a -> Pi/4; triangle = Partition[Flatten[Table[matrix.{i, j - n}, {j, 0, n}, {i, 0, j}]], 2]; path = matrix.# & /@ Prepend[ Accumulate[{#, # - 1} & /@ Take[ Join[ Table[0, {nn}], Reverse[Permutations[ Join[Table[1, {k}], Table[0, {nn - k}]]] ] [[m]] ], -nn] ], {0, 0} ]; Graphics[{ RGBColor[.33, .26, .78], Circle[#, .5] & /@ triangle, If[k <= nn && m <= Binomial[nn, k], {RGBColor[1, .47, 0], PointSize[.02], Disk[#, .4] & /@ path}, {}], Text["A", path[[ 1]] ] }, PlotRange -> All, PlotLabel -> If[ Binomial[nn, k] == 1, Style[ Row[{"\n", Binomial[nn, k], " possible path from A to B"}], "Label"], Style[ Row[{"\n", Binomial[nn, k], " possible paths from A to B"}], "Label"] ], ImageSize -> {500, 372}, opts ] ]; Manipulate[ m = Max[1, Min[m, Binomial[nn, k]]]; nn = Min[n, -Round[(Sqrt[2] pt[[2]])]]; k = Quiet@ Min[First@ First[Position[Table[i, {i, -nn, nn, 2}], Round[(Sqrt[2] pt[[1]])]]] - 1, nn]; pt = First@ Nearest[N /@ Partition[ Flatten[Table[({{Cos[a], Sin[a]}, {-Sin[a], Cos[a]}} /. a -> Pi/4).{i, j - n}, {j, 0, n}, {i, 0, j}]], 2], pt]; Column[{LocatorPane[ Dynamic[pt, (pt = First@Nearest[ N /@ Partition[ Flatten[ Table[({{Cos[a], Sin[a]}, {-Sin[a], Cos[a]}} /. a -> Pi/4).{i, j - n}, {j, 0, n}, {i, 0, j}]], 2], #]) &], Dynamic@CountingPaths[k, n, nn, m], Appearance -> Text@Style["B", Blue]]}], {{m, 1, "the possible paths"}, 1, Binomial[nn, k], 1, Appearance -> "Labeled"}, {{k, 3}, 0, nn, 1, ControlType -> None}, {{nn, 6}, 0, n, 1, ControlType -> None}, {{n, 6, "number of rows n"}, 0, 16, 1, Appearance -> "Labeled"}, {{pt, {0, -3}}, {-n, -n}, {n, 0}, ControlType -> None}, SaveDefinitions -> True, AutorunSequencing -> {1, 4}]
จากโปรแกรมข้างต้นค่ะ หนูอยากรู้ว่ามันทำอะไร แล้ว output ที่ได้มันคืออะไร หนูนั่งมองตั้งนานแต่ก็ไม่เข้าใจว่ามันคืออารทำงานของอะไร หรือมันยากเกินไปที่เด็กมัธยมอย่างหนูจะเข้าใจ ใครสามารถช่วยอธิบายให้หนู้ได้ จักขอบพระคุณอย่างยิ่งค่ะ
ยิ่งอธิบายแต่ละบรรทัดเลย ยิ่งดีค่ะ
|