3
$\begingroup$

This question already has an answer here:

I have the following code that simulates an Ito process in Mathematica,

a = .3;
μ = 0.2;
c = .1;
σ = 0.1;
sol = RandomFunction[
   ItoProcess[{\[DifferentialD]s[t] == -a s[t] i[
        t] \[DifferentialD]t, \[DifferentialD]i[
        t] == (a s[t] i[t] - μ i[t] + 
          c (1 - s[t] - i[t]) i[t]) \[DifferentialD]t + σ i[
         t] \[DifferentialD]W[t]}, {s[t], i[t]}, {{s, i}, {0.5, 0.5}},
     t, W \[Distributed] WienerProcess[0, 1]], {0, 30, 0.01}];

grafsolesto = 
 ListLinePlot[sol, PlotStyle -> {Thickness[Medium]}, PlotRange -> All,
   PlotTheme -> "Scientific", ImageSize -> Medium, 
  FrameLabel -> (Style[#, 12, Bold] & /@ {"t", "População"}), 
  PlotLegends -> 
   LineLegend[{Orange, {Red, Blue}}, {Style["S(t)", Bold, 12], 
     Style["I(t)", Bold, 12]}]]

but it yields just one path in my simulation.

What I really want is to simulate several paths and plot them with the mean value and the standard deviation in the same graph.

How could I do this? What I want is something like the following:

Plot taken from wolfram documentation

Ps: I tried to set the number of paths after the last argument of randomfunction, but it doensn't work.

$\endgroup$

marked as duplicate by rhermans, Community Jul 18 '18 at 8:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3
$\begingroup$
sol2 = RandomFunction[ItoProcess[{\[DifferentialD]s[t] == -a s[t] i[t] \[DifferentialD]t,
    \[DifferentialD]i[t] == (a s[t] i[t] - μ i[t] +                   
      c (1 - s[t] - i[t]) i[t]) \[DifferentialD]t + σ i[t] \[DifferentialD]W[t]},
     {s[t], i[t]}, {{s, i}, {0.5, 0.5}},
    t, W \[Distributed] WienerProcess[0, 1]], {0, 30, 0.01}, 5];

grafsolesto2 = ListLinePlot[Join @@ (Normal /@ sol2["PathComponents"]), 
    PlotStyle -> {Thickness[Medium]}, PlotRange -> All, 
   PlotTheme -> "Scientific", ImageSize -> 500, 
    FrameLabel -> (Style[#, 12, Bold] & /@ {"t", "População"}), 
    PlotLegends -> Join[Subscript["S", #][t] & /@ Range[5], 
        Subscript["I", #][t] & /@ Range[5]]];

mstd = ListLinePlot[Join @@ ({ Mean[#], Mean[#] - 2 StandardDeviation[#], 
       Mean[#] + StandardDeviation[#]} & /@ Normal /@ sol2["PathComponents"]), 
    PlotStyle -> {Thickness[Large], Thin, Thin}, PlotRange -> All, 
    Filling -> {2 -> {3}, 5 -> {6}}];

Show[grafsolesto2, mstd]

enter image description here

$\endgroup$
  • $\begingroup$ What about the mean (standard deviation) curve? $\endgroup$ – Herr Schrödinger Jul 18 '18 at 8:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.