1

I am quite new to Mathematica, please help me struggling out of this question.

I want to know how the HNO3 and HNO2 change in the system.

first, I put the kinetics of some reactions:

knitricprod = 6*10^8;
knitricconsumed = 1.46*10^10;
NO3radicalproduction = 2.271*10^-6;
HNO2production = 2.072*10^-5;

then,I wrote the equations:

NO3eqns = {NO3'[t] == (-knitricprod*proton[t]*NO3[t]) + 
     knitricconsumed*HNO3[t] - NO3radicalproduction, NO3[0] == 0};
HNO3eqns = {HNO3'[t] == 
    knitricprod*proton[t]*NO3[t] + (-knitricconsumed*HNO3[t]) - 
     HNO2production, HNO3[0] == 0.2};
protoneqns = {proton'[t] == (-knitricprod*proton[t]*NO3[t]) + 
     knitricconsumed*HNO3[t], proton[0] == 0};
HNO2eqns = {HNO2'[t] == HNO2production, HNO2[0] == 0};
NO3radicaleqns = {NO3radical'[t] == NO3radicalproduction, 
   NO3radical[0] == 0};

Next,join them together:

eqns = Join[NO3eqns, HNO3eqns, protoneqns, HNO2eqns, NO3radicaleqns];
soln = NDSolve[
   eqns, {NO3, HNO3, proton, HNO2, NO3radical}, {t, 0, 20000}];

BUT, a error came out. NDSolve::nderr: Error test failure at t == 5082.429032772312`; unable to continue.

The fowllowing is my remaining code:

NO3pfunc[t_] = NO3[t] //. soln;
HNO3pfunc[t_] = HNO3[t] //. soln;
protonpfunc[t_] = proton[t] //. soln;
HNO2pfunc[t_] = HNO2[t] //. soln;
NO3radicalpfunc[t_] = NO3radical[t] //. soln;

Plot[NO3pfunc[xs] // Evaluate, {xs, 0, 20000}, PlotRange -> All, AxesLabel -> {"Time/s", "NO3 anion concentration/M"}] Plot[HNO3pfunc[xs] // Evaluate, {xs, 0, 20000}, PlotRange -> All, AxesLabel -> {"Time/s", "Nitric acid concentration/M"}] Plot[protonpfunc[xs] // Evaluate, {xs, 0, 20000}, PlotRange -> All, AxesLabel -> {"Time/s", "proton concentration/M"}] Plot[HNO2pfunc[xs] // Evaluate, {xs, 0, 20000}, PlotRange -> All, AxesLabel -> {"Time/s", "Nitrous acid concentration/M"}] Plot[NO3radicalpfunc[xs] // Evaluate, {xs, 0, 20000}, PlotRange -> All, AxesLabel -> {"Time/s", "NO3radical concentration/M"}]

Michael E2
  • 235,386
  • 17
  • 334
  • 747
Tracy
  • 11
  • 1
  • 2
    I changed knitricprod = 6*10^8;knitricconsumed = 146/100*10^10;NO3radicalproduction = 2271/1000*10^-6;HNO2production = 2072/1000*10^-5; and changed 0.2 to 2/10 in one of your equations so every decimal constant became an exact rational constant and then soln = NDSolve[eqns, {NO3, HNO3, proton, HNO2, NO3radical}, {t, 0, 20000},WorkingPrecision->64,MaxSteps->10^6] and it completes without warnings or errors. Check that result VERY carefully to determine if it might be correct. – Bill Jul 23 '21 at 01:55
  • Search on "Error Test Failure" to see the many different situations in which it can occur. Often, seemingly inconsequential changes to the code eliminate it. – bbgodfrey Jul 23 '21 at 02:21
  • 2
    Try MaxStepSize -> 400 and see if it looks right. (Hint came from here and the step-size data produced by NO3["Grid"] /. First[soln] // Differences // Take[#, -10] &.) – Michael E2 Jul 23 '21 at 04:00
  • 2
    The first 80 steps or so show some extremely rapid movement of NO3, HNO3, and proton compared to the rest of the integration. Might be worth checking out. – Michael E2 Jul 23 '21 at 04:19
  • 1
    If you follow Bill's or Michael E2's advice, the system produces negative concentrations. Often, this indicates there is an error in your underlying kinetic mechanism. Perhaps you could add the intended mechanism to your question. – Tim Laska Jul 23 '21 at 17:05

0 Answers0