Advertisement
Matthen

Chasing

Apr 16th, 2016
1,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. Clear[x]; Clear[y];
  2. x[0][t_] := Sin[2 Pi t];
  3. y[0][t_] := Cos[2 Pi t];
  4. \[Rho] = 0.9;
  5. n = 10;
  6. T = n + 2;
  7. \[Epsilon] = 10^-3;
  8. NormedVectorX[{x_, y_}] :=
  9. If[Norm[{x, y}] > \[Epsilon], x/Norm[{x, y}], x];
  10. NormedVectorY[{x_, y_}] :=
  11. If[Norm[{x, y}] > \[Epsilon], y/Norm[{x, y}], y];
  12. eqns = Flatten@Table[
  13. {
  14. x[i][0] == 0, y[i][0] == 0,
  15. D[x[i][t], t] ==
  16. If[t > i, 2 Pi, 0] \[Rho] ^
  17. i NormedVectorX[( {x[i - 1][t], y[i - 1][t]} - {x[i][t],
  18. y[i][t]})],
  19. D[y[i][t], t] ==
  20. If[t > i, 2 Pi, 0] \[Rho] ^
  21. i NormedVectorY[( {x[i - 1][t], y[i - 1][t]} - {x[i][t],
  22. y[i][t]})]
  23. }
  24. , {i, n}];
  25. soln = NDSolve[eqns, Flatten@Table[{x[i], y[i]}, {i, n}], {t, 0, T}];
  26. dt = 0.01;
  27. Manipulate[
  28. Graphics[{
  29. Thickness[Medium],
  30. Table[
  31. {ColorData["RedBlueTones"][i/n],
  32. Line[Table[{x[i][t], y[i][t]}, {t, 0, tmax, 0.01}]]}
  33. , {i, 0, n}],
  34. PointSize[Medium],
  35. Table[
  36. {
  37. Darker@ColorData["RedBlueTones"][i/n],
  38. Point[{x[i][tmax], y[i][tmax]}]},
  39. {i, 0, n}]
  40. } /. soln, PlotRange -> 1, ImagePadding -> 5]
  41. ,
  42. {{tmax, T}, 0.01, T, dt}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement