0
$\begingroup$

Consider the following dataset:

    Data1 = {{0.04000000000000001, 3.6730181515774437*^-19, 
  0.0011366457254822827, 60968.11540339052, 2.1236323916037964*^-14, 
  0.000024533464278266223, 
     6.05793658772411*^-10}, {0.04286077220950427, 
  3.5735320748337414*^-18, 0.0011367866249206487, 74019.86038013306, 
  9.44320381587328*^-13, 
     0.000029966921646068634, 
  6.061648458859923*^-10}, {0.045926144859875326, 
  3.255424981728174*^-17, 0.0011369527269621297, 90053.88090726305, 
     3.286154294358077*^-11, 0.00003658039668686287, 
  6.070080518990282*^-10}, {0.049210750832495286, 
  2.5341104165796417*^-16, 0.0011371790768826945, 
     109594.1604424725, 9.081851407892915*^-10, 
  0.00004461671001039301, 6.085482546231459*^-10}, 
   {0.05273026954225631, 1.7149288047460928*^-15, 
  0.00113750204533264, 133531.87119944708, 2.0260455365402744*^-8, 
  0.00005562012741315951, 
     6.109252168769861*^-10}, {0.056501501784910174, 
  1.050519972446482*^-14, 0.001137926591272428, 163230.9619786704, 
  3.7090463605171533*^-7, 
     0.00006760933834508163, 
  6.144275485232054*^-10}, {0.06054244993744833, 
  5.785126177289693*^-14, 0.0011385002529520187, 199962.7324694581, 
     5.640895974410171*^-6, 0.00008210446936595845, 
  6.198175525381558*^-10}, {0.06487240389435721, 
  2.859704227057019*^-13, 0.001139310302677116, 
     246401.4495066501, 0.00007243730639484008, 
  0.0000996480849338258, 6.276535512220924*^-10}, 
   {0.06951203314997503, 1.2815620129762066*^-12, 
  0.0011405130800622618, 304616.8073825221, 0.0007925881290266281, 
  0.00012307121962089226, 
     6.380388322973216*^-10}, {0.07448348546651472, 
  5.269337715555936*^-12, 0.0011422281493432716, 379248.5567463476, 
  0.0074986358256308484, 
     0.00014928353005425407, 
  6.520750615794034*^-10}, {0.07981049259875521, 
  2.0074747616321736*^-11, 0.0011447257370502235, 474876.1413831532, 
     0.0618888614669688, 0.00018435323587895211, 
  6.700559990103894*^-10}, {0.08551848358008932, 
  7.05124504406454*^-11, 0.0011484669669138883, 
     598564.5009744188, 0.4502465359405161, 0.00022438799313786295, 
  6.925085322975094*^-10}, {0.09163470611071092, 
  2.3000740431526548*^-10, 
     0.0011540447823168796, 760828.7492393866, 2.9182068721657934, 
  0.0002785357086817402, 7.197104737969417*^-10}, 
   {0.09818835662740127, 7.024316848540299*^-10, 
  0.001162170287551631, 972405.9236193274, 16.94107794443051, 
  0.0003412477750141644, 
     7.520866142933496*^-10}, {0.10521071967581529, 
  2.0151537395464318*^-9, 0.0011739104100202753, 
  1.247297115624304*^6, 88.60424433247508, 
     0.0004271343315385529, 
  7.89111870149623*^-10}, {0.11273531725057817, 
  5.392959664617988*^-9, 0.0011917089463320113, 1.610428841403897*^6, 
     421.76716793957445, 0.0005373848560522533, 
  8.311068757370129*^-10}, {0.12079806881608067, 
  1.3662948531145418*^-8, 0.0012170983752536689, 
     2.088091105249584*^6, 1835.2807668292667, 0.0006794866268582713, 
  8.777148336817495*^-10}, 
   {0.12943746277185134, 3.26800243113598*^-8, 0.0012539678437698998, 
  2.7100656444720207*^6, 7322.4230773758245, 0.0008439764753236527, 
     9.2792356664838*^-10}, {0.13869474018101272, 
  7.424990724058318*^-8, 0.0013074352824174532, 
  3.5319312976799784*^6, 27030.38887883136, 
     0.00107442884253638, 
  9.813608946416635*^-10}, {0.14861409163886904, 
  1.6118549524558457*^-7, 0.0013834701962826016, 4.601653981863014*^6, 
     92413.4995937878, 0.001372210710456111, 
  1.0374440262624992*^-9}, {0.15924286822139894, 
  3.359117261965592*^-7, 0.001490640368191695, 
     6.003178262294154*^6, 294588.19867804437, 0.0017135443780015402, 
  1.0953659562222803*^-9}, 
   {0.1706318075206371, 6.768144438289502*^-7, 0.0016418145327914294, 
  7.818396651581257*^6, 877127.4857127845, 0.002195205293756092, 
     1.1534507078566864*^-9}, {0.18283527584595002, 
  1.3253825227723483*^-6, 0.0018530825010397774, 
  1.019158194753562*^7, 2.456545832150365*^6, 
     0.0028160341031557017, 
  1.2118127587928474*^-9}, {0.1959115277473785, 
  2.541882634404852*^-6, 0.00214520506148593, 1.3264692068722617*^7, 
     6.482556887839657*^6, 0.003519077495772852, 
  1.2698477884419106*^-9}, {0.2099229840999091, 
  4.7973894775465834*^-6, 0.0025485871023961408, 
     1.7206929419349123*^7, 1.6151997002525678*^7, 
  0.004514855063665674, 1.3254573346580083*^-9}, 
   {0.2249365300761397, 8.938280979270732*^-6, 0.0031021976669112004, 
  2.23159353128588*^7, 3.825493075573033*^7, 0.0057928643041654975, 
     1.3796925661487545*^-9}, {0.24102383442974318, 
  0.000016491104414852177, 0.0038603290769480118, 
  2.8896676575433616*^7, 8.629961187526782*^7, 
     0.007222131323891681, 
  1.431134731390959*^-9}, {0.25826169161386225, 
  0.00003013498762673002, 0.004891523184322172, 3.732919279303819*^7, 
     1.8586729491043442*^8, 0.009252005938239705, 
  1.4797712109910823*^-9}, {0.27673238836757463, 
  0.00005453864812818399, 0.00629183641986388, 
     4.820132037437235*^7, 3.840485105566199*^8, 
  0.011509316021565116, 1.5253491942476746*^-9}, 
   {0.2965240965203671, 0.00009761820733772267, 0.008186960442081337, 
  6.211483068339884*^7, 7.62191350054374*^8, 0.014713128474094301, 
     1.567646943405622*^-9}, {0.3177312938897126, 
  0.00017278324797833004, 0.010754393209756815, 7.995070777156478*^7, 
  1.4578452750520904*^9, 
     0.018257113197046024, 
  1.6064948687755004*^-9}, {0.34045521528095063, 
  0.00030185339768827715, 0.014218998372583154, 1.0280561154606108*^8, 
     2.694270360773067*^9, 0.023286894279490714, 
  1.6425896937056255*^-9}, {0.364804335742364, 0.0005209611648465304, 
  0.018911113696050464, 
     1.3198929410199991*^8, 4.819255315060689*^9, 
  0.028823919766414487, 1.6745715437867294*^-9}, 
   {0.3908948883823244, 0.0008861421412744314, 0.025231897306304558, 
  1.6937248053716332*^8, 8.369218172915381*^9, 0.035646186421712, 
     1.704347805240533*^-9}, {0.41885141922035996, 
  0.0014879128934780943, 0.03377408680912669, 2.170856889094142*^8, 
  1.412863001652607*^10, 
     0.045300933483077885, 
  1.7306844074866155*^-9}, {0.44880738172078555, 
  0.002466286434495853, 0.04531709865432165, 2.779592325864481*^8, 
     2.3232109573694702*^10, 0.05589725905096408, 
  1.7541752035026805*^-9}, {0.48090577384696537, 
  0.004035550166444166, 0.06090375420869664, 
     3.557989441565829*^8, 3.729891184286874*^10, 0.068922502945096, 
  1.7758023178809883*^-9}, 
   {0.5152998206772536, 0.0065283544138783406, 0.08200914283817416, 
  4.551490366083445*^8, 5.8540824576103294*^10, 0.08732573942051954, 
     1.7944955878185098*^-9}, {0.552153705841154, 
  0.010447781138129195, 0.11062036290904508, 5.814525939360955*^8, 
  8.98880028939501*^10, 
     0.107473843263601, 1.810895200404476*^-9}, {0.5916433552672831, 
  0.01653890680422021, 0.14935730557017074, 7.429912935755776*^8, 
     1.3543097497648143*^11, 0.13219796597640998, 
  1.8258944804728217*^-9}, {0.6339572769844455, 0.025937307600763675, 
  0.20196184017845184, 
     9.485638471332476*^8, 2.0024824008527032*^11, 
  0.16711888122276794, 1.8392419060443485*^-9}, 
   {0.6792974609846979, 0.04034700409506356, 0.2736029058694903, 
  1.2102237755567687*^9, 2.909885449151632*^11, 0.2052666582315007, 
     1.8501160265376655*^-9}, {0.7278803434439935, 
  0.06223137927350765, 0.37105306369630586, 1.542952475743961*^9, 
  4.160021805634737*^11, 
     0.25202295914652556, 
  1.8600321208203338*^-9}, {0.7799378399032184, 0.09523449582533373, 
  0.5037214290466892, 1.967536927419406*^9, 
     5.862404551266245*^11, 0.30932363965331905, 
  1.8691156000495226*^-9}, {0.8357184523416157, 0.14480564158746242, 
  0.6849656687466679, 
     2.505864555324614*^9, 8.139905161351083*^11, 
  0.39012767685654065, 1.876773077518704*^-9}, 
   {0.8954884554273358, 0.21895982027010316, 0.933214460922383, 
  3.724151664300324*^8, 1.3022394818294788*^11, 0.4783452882352051, 
     1.8829132235127783*^-9}, {0.9595331676077962, 
  0.32904532742184267, 1.272684547155989, 0., 0., 0.5863801024968948, 
  1.8885541302790296*^-9}, 
   {1.0281583131075456, 0.491691526418462, 1.737372694863958, 0., 0., 
  0.7186826843829303, 1.893783649743893*^-9}, 
   {1.1016914813352667, 0.7314024765782356, 2.375371032564205, 0., 
  0., 0.9051296290287619, 1.89819938884556*^-9}, 
   {1.1804836906665546, 1.084143824031097, 3.2543622222297746, 0., 
  0., 1.1085674226849835, 1.901325085222587*^-9}, 
   {1.264911064067352, 1.5998883370347974, 4.462773587712801, 0., 0., 
  1.3575721723418253, 1.904266253623223*^-9}, 
   {1.3553766245568106, 2.3514114854853303, 6.125519165240608, 0., 
  0., 1.6623947188858716, 1.9070847187327836*^-9}, 
   {1.4523122190804059, 3.443728902375022, 8.416725997772431, 0., 0., 
  2.0354856022589813, 1.9098278742932196*^-9}, 
   {1.5561805799771222, 5.032516360409247, 11.588651462598817, 0., 
  0., 2.560427181523345, 1.91113941530246*^-9}, 
   {1.6674775338813417, 7.33214391965452, 15.971903907103549, 0., 0., 
  3.1336127451840485, 1.912418218615513*^-9}, 
   {1.7867343686038526, 10.650675858898598, 22.029553714476762, 0., 
  0., 3.8350032698731886, 1.9137576280470963*^-9}, 
   {1.9145203692905537, 15.42848919710927, 30.406219045113726, 0., 
  0., 4.693382379212429, 1.9151902699813277*^-9}, 
   {2.0514455359654598, 22.307933788089844, 42.025296542578594, 0., 
  0., 5.901791123092204, 1.916091945714172*^-9}, 
   {2.198163495430499, 32.2024768282308, 58.16590582996733, 0., 0., 
  7.220190907338247, 1.9163661828847035*^-9}, 
   {2.3553746214223565, 46.38277596899167, 80.55347510295799, 0., 0., 
  8.833153973418863, 1.916815241910244*^-9}, 
   {2.5238293779207726, 66.66321598076935, 111.60824528756592, 0., 
  0., 10.806958855072507, 1.917460271190991*^-9}, 
   {2.704331901567927, 95.63932394751524, 154.73396954520854, 0., 0., 
  13.22196478822141, 1.9183224443280263*^-9}, 
   {2.89774384029996, 137.07433730712353, 214.81009502241022, 0., 0., 
  16.619302561317976, 1.9181898557929484*^-9}, 
   {3.104988466514767, 196.1806402623078, 298.4252892891094, 0., 0., 
  20.32801520638921, 1.918113460817766*^-9}, 
   {3.3270550844106843, 280.2875974453487, 414.6818354793054, 0., 0., 
  24.86543724283311, 1.918293258915911*^-9}, 
   {3.5650037525349827, 399.7939118353185, 576.321713145112, 0., 0., 
  30.417780148740146, 1.9187389207216093*^-9}, 
   {3.819970344085745, 569.6278736669964, 801.4852301693955, 0., 0., 
  38.23525046862454, 1.9191330343923305*^-9}, 
   {4.0931719691230155, 811.0975018471803, 1115.8267571796891, 0., 
  0., 46.762378621512134, 1.918730838682514*^-9}, 
   {4.385912784572741, 1153.3316551215432, 1553.6000912931834, 0., 
  0., 57.19531021750488, 1.9186088593139887*^-9}, 
   {4.699590219758118, 1637.6511861862862, 2162.97753372881, 0., 0., 
  69.95978712026677, 1.918774068782407*^-9}, 
   {5.035701647176671, 2322.235219808318, 3011.0662706314047, 0., 0., 
  85.57904613887125, 1.9192315658181652*^-9}, 
   {5.395851530366614, 3291.2413919769583, 4195.0990748257955, 0., 
  0., 107.56017693667187, 1.9191750141203098*^-9}};

I interpolate them:

jacobian[T_] = 
  Interpolation[Data1[[All, {1, 6}]], InterpolationOrder -> 1][T];
\[CapitalGamma]pn[T_] = 
  Interpolation[Data1[[All, {1, 2}]], InterpolationOrder -> 1][T];
\[CapitalGamma]np[T_] = 
  Interpolation[Data1[[All, {1, 3}]], InterpolationOrder -> 1][T];
\[CapitalGamma]npTod\[Gamma][T_] = 
  Interpolation[Data1[[All, {1, 4}]], InterpolationOrder -> 1][T];
\[CapitalGamma]d\[Gamma]Tonp[T_] = 
  Interpolation[Data1[[All, {1, 5}]], InterpolationOrder -> 1][T];
\[Eta]Bv[T_] = 
  Interpolation[Data1[[All, {1, 7}]], InterpolationOrder -> 1][T];

Then I want to solve a set of differential equations:

XdDynamics[Xn_, Xd_, T_] = 
  Xn*(1 - Xn - Xd)*\[CapitalGamma]npTod\[Gamma][T] - 
   Xd*\[Eta]Bv[T]^-1*\[CapitalGamma]d\[Gamma]Tonp[T];
XnDynamics[Xn_, Xd_, T_] = (1 - Xn - Xd) \[CapitalGamma]pn[T] - 
   Xn*\[CapitalGamma]np[T] - XdDynamics[Xn, Xd, T];
    sol = NDSolve[{D[Xn[T], T]*
         jacobian[T] == -XnDynamics[Xn[T], Xd[T], T], 
       D[Xd[T], T]*jacobian[T] == -XdDynamics[Xn[T], Xd[T], T], 
       Xd[4.9] == 0, Xn[4.9] == 0.5}, {Xn, Xd}, {T, 0.04, 4.9}]
    f = Xn /. sol[[1]]

However, Mathematica says

NDSolve::nderr: Error test failure at T == 0.841822; unable to continue

The point 0.8418... is the maximal point when the functions \[CapitalGamma]npTod\[Gamma], \[CapitalGamma]npTod\[Gamma] are non-zero.

Could you please tell me how to avoid this error?

P.S. Changing the method to StiffnessSwitching removes the error. However, the solution behaves badly, so this, unfortunately, does not help.

P.P.S. It seems that decreasing MaxStepSize matters. I've set MaxStepSize -> 0.5*10^-4, and the solution has been obtained. However, it now requires much more time for solving. This will increase the solving time after increasing the number of equations. Is there any alternative method of getting the solution without spending such an amount of time?

$\endgroup$
  • 2
    $\begingroup$ First, I get a different error, NDSolve::ndsz. Second when I try, Method -> "StiffnessSwitching" (suggested by the error), it works. (V12.1.1, Mac) $\endgroup$ – Michael E2 Jul 30 at 21:17
  • 2
    $\begingroup$ @MichaelE2 : excuse me, initially I have copied an incorrect piece of code. Now the code is correct. $\endgroup$ – John Taylor Jul 30 at 21:19
  • $\begingroup$ If the solution behaves badly, it may be that the code or data is in error. By the way, the definitions of XdDynamics and XnDynamics differ in two blocks of coce. $\endgroup$ – bbgodfrey Jul 30 at 23:54
  • $\begingroup$ @bbgodfrey : corrected the code problem. $\endgroup$ – John Taylor Jul 31 at 8:03
  • 2
    $\begingroup$ These problems are due to the enormous abrupt changes in your data just below T = 1, which you could point out in the question. Running the computation to that point and only then reducing the time step could save you a factor of five or so in runtime. WhenEvent also might help, although I am not sure how. By the way, I needed , MaxStepSize -> 10^-5 to avoid error messages. $\endgroup$ – bbgodfrey Jul 31 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.