Advertisement
Wojtekd

Modelowanie2

May 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. r = 0.1;
  2. x0 = 0;
  3. y0 = 0;
  4. z0 = powierzchnia[x0, y0];
  5. listaKatow = Table[RandomReal[{0, 2 Pi}], {i, 500}];
  6. powierzchnia[x_, y_] = 2 x + 3 y^2;
  7. f[x_, y_, xp_, yp_,
  8.    zp_] = (x - xp)^2 + (y - yp)^2 + (2 x + 3 y^2 - zp)^2 - r^2;
  9.  
  10. i = 1;
  11. points = {};
  12.  
  13. While[i <= 500, alfa = listaKatow[[i]];
  14.  Result =
  15.   FindInstance[{(y - y0)*Cos[alfa] - (x - x0)*Sin[alfa] == 0,
  16.     f[x, y, x0, y0, z0] == 0}, {x, y}, Reals, 2];
  17.  xPunktu = Result[[1, 1, 2]];
  18.  yPunktu = Result[[1, 2, 2]];
  19.  zPunktu = powierzchnia[xPunktu, yPunktu];
  20.  pointCurrent = {xPunktu, yPunktu, zPunktu};
  21.  xPunktu2 = Result[[2, 1, 2]];
  22.  yPunktu2 = Result[[2, 2, 2]];
  23.  zPunktu2 = powierzchnia[xPunktu2, yPunktu2];
  24.  pointCurrent =
  25.   RandomChoice[{{xPunktu, yPunktu, zPunktu}, {xPunktu2, yPunktu2,
  26.      zPunktu2}}];
  27.  points = Append[points, pointCurrent];
  28.  x0 = pointCurrent[[1]];
  29.  y0 = pointCurrent[[2]];
  30.  z0 = pointCurrent[[3]];
  31.  i++;]
  32.  
  33.  
  34. rows = List[];
  35. n = 1;
  36. While[n <= 500,
  37.  r0 = points[[n, 1]]^2 + points[[n, 2]]^2 + points[[n, 3]]^2;
  38.  rows = Append[rows, {r0, n, r0/n}];
  39.  n = n + 1]
  40.  
  41. srednia = Mean[rows[[All, 3]]];
  42. odchylenie = StandardDeviation[rows[[All, 3]]];
  43.  
  44. Print["Średnia:", srednia];
  45. Print["Odchylenie standardowe:", odchylenie];
  46.  
  47. rows = Insert[rows, {"r^2", "t", "r^2/t"}, 1];
  48. Grid[rows[[;; ;; 10]], Frame -> All]
  49.  
  50.  
  51. Animate[Show[
  52.   Plot3D[{2 x + 3 y^2}, {x, -1, 1}, {y, -1, 1},
  53.    BoxRatios -> {1, 1, 1}],
  54.   Graphics3D[{Green, PointSize[.02], Line[points[[;; it]]],
  55.     Point[points[[it]]]}]], {it, 1, 500, 1}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement