Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. (*Simulation Parameters and definitions*)
  2. (*---------------------------------*)
  3. Clear[f]
  4. Clear[i, P, B]
  5. f[P_, B_] := 1/2 P + 10 B/(1 + B);
  6. tmax = 25;
  7. eps = 0.001;
  8. randNum = 100;
  9. A = {{1/20, 1/4, 1/50}, {1/4, 1/26, 1/40}};
  10. point = {16.666666666666735`, 0.`, 8.333333333333345`};
  11.  
  12. (*ODE System*)
  13. ODEsys = {i'[t] == f[P[t], B[t]] - i[t],
  14. P'[t] ==
  15. P[t] (1 - A[[1, 1]] P[t] - A[[1, 2]] B[t] - A[[1, 3]] i[t]),
  16. B'[t] == B[t] (1 - A[[2, 2]] B[t] - A[[2, 3]] i[t])};
  17.  
  18. (*Generating parametric g curve.*)
  19. (* Consider this section a *)
  20. (*--------------------------*)
  21. set = List[];
  22.  
  23. While[Length[set] < randNum,
  24. holdSet =
  25. Join[set, Map[point + # &, RandomReal[{-eps, eps}, {randNum, 3}]]];
  26. set = Select[holdSet, #[[2]] >= 0 &];]
  27.  
  28. set = Drop[set, -(randNum - Length[set])];
  29.  
  30. (*Simulation*)
  31. sol = ParametricNDSolveValue[{ODEsys, {P[0] == init1, B[0] == init2,
  32. i[0] == init0}}, {P, B, i}, {t, 0, tmax}, {init1, init2, init0}];
  33.  
  34. (*Averging solution over multiple inital conditions.*)
  35. gCurve[t_] :=
  36. Evaluate[Mean[Through /@ (sol[#[[1]], #[[2]], #[[3]]][t] & /@ set)]];
  37. gPlot = ParametricPlot3D[gCurve[t], {t, 0, tmax}, PlotRange -> All,
  38. ImageSize -> Large, PlotStyle -> Black];
  39.  
  40. (* Plot tubes of varying radiuses *)
  41. (*----------------------------*)
  42.  
  43. (* Function which varies radius along the tube *)
  44. radialfun[x_, radius_] := radius (Abs[x - 25]/50)^(1.20);
  45.  
  46. (* Controls the number of points plotted, 600+ gives a high quality
  47. plot *)
  48. numPoints = 50;
  49.  
  50. (* Controls opacity *)
  51. a = 0.2;
  52.  
  53. {plot, vals} =
  54. Reap[ParametricPlot3D[gCurve[t], {t, 0, tmax},
  55. EvaluationMonitor :> Sow[t], MaxRecursion -> 0,
  56. Method -> {"TubePoints" -> numPoints}, PlotPoints -> numPoints,
  57. PlotStyle -> RGBColor[0., 0.5, 0.73, a] ]];
  58. (* Plot different level sets of tubes*)
  59. TubePlot1 =
  60. plot /. Line[pts_, rest___] :>
  61. Tube[pts, radialfun[vals[[1]], 1], rest];
  62. TubePlot2 =
  63. plot /. Line[pts_, rest___] :>
  64. Tube[pts, radialfun[vals[[1]], 4], rest];
  65. TubePlot3 =
  66. plot /. Line[pts_, rest___] :>
  67. Tube[pts, radialfun[vals[[1]], 10], rest];
  68. TubePlot4 =
  69. plot /. Line[pts_, rest___] :>
  70. Tube[pts, radialfun[vals[[1]], 15], rest];
  71.  
  72. (*Show the plots of the different level tube sets*)
  73. Show[gPlot, TubePlot1, TubePlot2, TubePlot3, TubePlot4,
  74. LabelStyle -> Automatic, BoxStyle -> Dashing[{0.02, 0.02}],
  75. Boxed -> None, PlotRangePadding -> 0, AxesOrigin -> Automatic,
  76. AxesEdge -> {{1, 1, 1}, None, Automatic}, Ticks -> Automatic,
  77. AxesStyle -> Thickness[0.005], ImageSize -> Large,
  78. ImageResolution -> Automatic, PlotRangeClipping -> True,
  79. PlotRange -> {{0, Automatic}, {0, Automatic}, {0, Automatic}}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement