If I have a system of differential equations, I solve it and save the result in Sol
:
Clear[a, b, S0, I0];
a = .0015; b = .9; S0 = 1000; I0 = 10; tmax = 20;
t0 = 0;
Sol = NDSolve[{S'[t] == -a*II[t]*S[t],
II'[t] == a*II[t]*S[t] - b*II[t], S[0] == S0, II[0] == I0}, {S[t],
II[t]}, {t, 0, tmax}]
For II[t], the graph is correct, which demonstrates that the result is also correct.
Then, I want to plot the graph of $\int_{t0}^{t} II[t] dt$. The domain of the graph should be [-10, 60].
Plot[NIntegrate[Evaluate[II[t] /. Sol], {t, t0, tmax}], {t, 0, tmax},
AspectRatio -> .5, AxesLabel -> {"t", "I(t)"}, PlotRange -> All,
AxesOrigin -> {0, 0}]
It is obviously wrong.
I was wondering what the problem is here, and how I should perform the integration.
NDSolve
is wrong. Please look up the correct syntax in the documentation forNDSolve
to make that work. Also, you need to specify all numerical parameters. What are the values ofa
,b
, etc.? $\endgroup$NDSolve
code with the values for the parameters is necessary so that we can run the code on our own copies of Mathematica and tinker with it to figure out a solution to your problem. $\endgroup$Plot[NIntegrate[Evaluate[II[tp] /. Sol], {tp, t0, t}], {t, 0, tmax}, AspectRatio -> .5, AxesLabel -> {"t", "I(t)"}, PlotRange -> All, AxesOrigin -> {0, 0}]
$\endgroup$ListLinePlot[Head@Integrate[II[t] /. First@Sol, t], AspectRatio -> .5, AxesLabel -> {"t", "I(t)"}, PlotRange -> All, AxesOrigin -> {0, 0}]
$\endgroup$