I want to plot the decay of $O_3$ to $O_2$.

My system and my code (x = $O_3$, y = $O_2$):

ozonProb = {x'[t]==-x[t]-x[t]*y[t]+ϵ*k*y[t], 
loes = NDSolve[ozonProb, {x, y}, {t, 0, 240}]

Now when I plot my $O_3$ or $O_2$ concentration:

Plot[x[t]/.loes, {t, 0, 2922}]

both of them reach a negative value after ~2 years. Is there a problem in my system?


closed as off-topic by Michael E2, user9660, MarcoB, Bob Hanlon, m_goldberg Jan 9 '16 at 17:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, Community, MarcoB, Bob Hanlon, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ Your Plot extends outside the domain of the NDSolve solution requested, i.e., {t, 0, 240}. $\endgroup$ – Bob Hanlon Jan 9 '16 at 15:59
ϵ = 98;
k = 3;
ozonProb = {x'[t] == -x[t] - x[t]*y[t] + ϵ*k*y[t], 
   y'[t] == x[t]*((1 - y[t])/ϵ) - k*y[t], x[0] == 1, 
   y[0] == 0};
loes = NDSolve[ozonProb, {x, y}, {t, 0, 2922}];

Plot[Evaluate[{x[t], 100 y[t]} /. loes], {t, 0, 2922}]

enter image description here


You solved your system in the range 0 .. 240 but your plot is in the range 0 .. 2922 . You got extrapolation difficulties.

Addendum to your question

loes2 = NDSolve[ozonProb, {x, y}, {t, 0, 3}];

 Plot[Evaluate[{x[t], 100 y[t]} /. loes2], {t, 0, 3}],
 Plot[Evaluate[{x[t], 100 y[t]} /. loes], {t, 0, 3}]

enter image description here

It is sufficient to solve the system in the range 0 ..2922 once.

  • 3
    $\begingroup$ No explanation? $\endgroup$ – Michael E2 Jan 9 '16 at 13:27
  • $\begingroup$ Rewi, please comment on the changes you made in the OP's code that fixed the original problem (e.g. You extended the domain over which NDSolve operated, etc). $\endgroup$ – MarcoB Jan 9 '16 at 16:01
  • $\begingroup$ thank you :) If I want to use loes for i.e. {t,0,3} and {t,0,2922}, would it be better to define a Block for loes/use NDSolve twice (to get better WorkingPrecision i.e.?) or is it ok, if I use NDSolve with 2922 (the maximum time value) and plot in a range from 0 to 3 too? $\endgroup$ – gumpel Jan 9 '16 at 16:44
  • $\begingroup$ @MarcoB Sorry, I thought that the code is easy to understand. $\endgroup$ – user36273 Jan 9 '16 at 16:45
  • $\begingroup$ When you see the error, it's easy to understand. When you don't see the error, it's not; and a simple explanation in this case makes it obvious and easy for others. (+1) -- Side note: The old Plot use to let warnings about extrapolation escape, which would probably have solved it for the OP before posting. $\endgroup$ – Michael E2 Jan 9 '16 at 16:57

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