# Avoid crashing kernel by NDsolve

I would like to numerically solve set of diff. eq. with various int. conditions, the problem is for some combitaions of them NDSovle crashes so as the kernel. Is there any possibility to avoid it ? I have chcecked Evaluation control, but nothing seem to avoid the crashing.

For example: this conf:

   {Equations, IntCond} ={{Derivative[r][τ] ==
pr[τ] (1 - 2/r[τ])^0.4 ((-2 r[τ] +
r[τ]^2)/(-2 r[τ] + r[τ]^2 +
Sin[θ[τ]]^2))^0.84,
Derivative[
pr][τ] == -(0.484709/((1 - 2/r[τ])^1.4 r[τ]^2)) - (
0.4 pr[τ]^2 ((-2 r[τ] + r[τ]^2)/(-2 r[τ] +
r[τ]^2 + Sin[θ[τ]]^2))^0.84)/((1 - 2/
r[τ])^0.6 r[τ]^2) + (
0.42 pθ[τ]^2 (1 - 2/r[τ])^0.4 (-2 +
2 r[τ]))/((-2 r[τ] +
r[τ]^2)^0.16 (-2 r[τ] + r[τ]^2 +
Sin[θ[τ]]^2)^1.84) + (
0.08 pθ[τ]^2 (1 - 2/r[τ])^0.4 (-2 +
2 r[τ]))/((-2 r[τ] +
r[τ]^2)^1.16 (-2 r[τ] + r[τ]^2 +
Sin[θ[τ]]^2)^0.84) - (
0.4 pθ[τ]^2)/((1 - 2/
r[τ])^0.6 r[τ]^2 (-2 r[τ] +
r[τ]^2)^0.16 (-2 r[τ] + r[τ]^2 +
Sin[θ[τ]]^2)^0.84) - (
Csc[θ[τ]]^2 (1 - 2/
r[τ])^0.4 (0.14 (-2 +
r[τ])^0.6 r[τ]^0.4 Sin[θ[τ]]^2 + (
0.06 r[τ]^1.4 Sin[θ[τ]]^2)/(-2 +
r[τ])^0.4) (0.641512 +
0.1 (-2 +
r[τ])^0.6 r[τ]^1.4 Sin[θ[τ]]^2))/(-2
r[τ] + r[τ]^2) + (
Csc[θ[τ]]^2 (1 - 2/r[τ])^0.4 (-2 +
2 r[τ]) (0.641512 +
0.1 (-2 +
r[τ])^0.6 r[τ]^1.4 Sin[θ[τ]]^2)^2)/(
2 (-2 r[τ] + r[τ]^2)^2) - (
0.4 Csc[θ[τ]]^2 (0.641512 +
0.1 (-2 +
r[τ])^0.6 r[τ]^1.4
Sin[θ[τ]]^2)^2)/((1 - 2/
r[τ])^0.6 r[τ]^2 (-2 r[τ] + r[τ]^2)) - (
0.42 pr[τ]^2 (1 - 2/
r[τ])^0.4 (-(((-2 + 2 r[τ]) (-2 r[τ] +
r[τ]^2))/(-2 r[τ] + r[τ]^2 +
Sin[θ[τ]]^2)^2) + (-2 +
2 r[τ])/(-2 r[τ] + r[τ]^2 +
Sin[θ[τ]]^2)))/((-2 r[τ] +
r[τ]^2)/(-2 r[τ] + r[τ]^2 +
Sin[θ[τ]]^2))^0.16,
Derivative[θ][τ] == (
pθ[τ] (1 - 2/r[τ])^0.4)/((-2 r[τ] +
r[τ]^2)^0.16 (-2 r[τ] + r[τ]^2 +
Sin[θ[τ]]^2)^0.84),
Derivative[pθ][τ] == (
0.84 Cos[θ[τ]] pr[τ]^2 (1 - 2/
r[τ])^0.4 (-2 r[τ] +
r[τ]^2) Sin[θ[τ]])/(((-2 r[τ] +
r[τ]^2)/(-2 r[τ] + r[τ]^2 +
Sin[θ[τ]]^2))^0.16 (-2 r[τ] + r[τ]^2 +
Sin[θ[τ]]^2)^2) + (
0.84 Cos[θ[τ]] pθ[τ]^2 (1 - 2/
r[τ])^0.4 Sin[θ[τ]])/((-2 r[τ] +
r[τ]^2)^0.16 (-2 r[τ] + r[τ]^2 +
Sin[θ[τ]]^2)^1.84) - (
0.2 Cot[θ[τ]] (1 - 2/r[τ])^0.4 (-2 +
r[τ])^0.6 r[τ]^1.4 (0.641512 +
0.1 (-2 +
r[τ])^0.6 r[τ]^1.4 Sin[θ[τ]]^2))/(-2
r[τ] + r[τ]^2) + (
Cot[θ[τ]] Csc[θ[τ]]^2 (1 - 2/
r[τ])^0.4 (0.641512 +
0.1 (-2 +
r[τ])^0.6 r[τ]^1.4
Sin[θ[τ]]^2)^2)/(-2 r[τ] + r[τ]^2),
Derivative[ϕ][τ] ==
0.1 + (0.641512 Csc[θ[τ]]^2 (1 - 2/
r[τ])^0.4)/(-2 r[τ] + r[τ]^2)}, {r == 6,
pr == 0, θ == π/2,
pθ == 0, ϕ == 0}};


and then e.g.

myMethod = {"FixedStep",
Method -> {"ExplicitRungeKutta",
"DifferenceOrder" -> 4}}; stepsize = 10^-2;

NDSolve[{Equations, IntCond}, {r, pr, θ,
pθ, ϕ}, {τ, 0,
xEND}, {Method -> {"EventLocator",
"Event" -> {r[τ] - 2, r[τ] - 1000},
"EventAction" :> {Throw[ Null, "StopIntegration"],
Throw[Null, "StopIntegration"]}, "Method" -> myMethod}}];


On my machine this crashes, but then another init. conds and ODE parameters produces a numerical solution, is there any chance to just mark the set of init. conds. as a non-existing num. and not to crash. It is necesery for automatized caluclation in order not to lose previous results.

• Why not use WhenEvent? (IDK if that's the problem.) – Michael E2 Mar 30 at 14:35
• Did you mean to include StartingStepSize -> stepsize or did you omit it on purpose? – Michael E2 Mar 30 at 14:38
• Your code does not run (some missing definitions like xEND). There seems to be nothing wrong with the code on the face of it. – Michael E2 Mar 30 at 14:39
• With these initial models, the finite motion describes. Therefore, the second event can not be. The first event also does not occur, because at the point $r=2, r'=0$. – Alex Trounev Mar 30 at 15:55
• Thanks for comments ! I was considering WhenEvent, but I dont know how to howt to use it to prevent crashing. To StartingStepSize -> stepsize I have tried it, but it doesnt seem to help. Actually xEND is important factor - the integration time, as I have found out, for some parameters I can get a solution till some Integration time let say, sometimes when xEND = 2000, I get a trajectory, whem more, it crashes. – user244980 Apr 1 at 6:29
{"ft_lang_label":"__label__en","ft_lang_prob":0.5479712,"math_prob":0.99969673,"size":3366,"snap":"2019-51-2020-05","text_gpt3_token_len":1775,"char_repetition_ratio":0.2676978,"word_repetition_ratio":0.19301471,"special_character_ratio":0.6063577,"punctuation_ratio":0.13721414,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9999676,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-09T14:21:55Z\",\"WARC-Record-ID\":\"<urn:uuid:1dc9e398-9436-4d78-b517-e7ed10ac8c6b>\",\"Content-Length\":\"133062\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ca9883ca-68a7-4ed9-9cab-461cb591e58c>\",\"WARC-Concurrent-To\":\"<urn:uuid:e964d494-6bcc-43d5-af0a-afa2d7d0ae5e>\",\"WARC-IP-Address\":\"151.101.129.69\",\"WARC-Target-URI\":\"https://mathematica.stackexchange.com/questions/194238/avoid-crashing-kernel-by-ndsolve\",\"WARC-Payload-Digest\":\"sha1:CMOHOTHLHYQQPBV553TOXAYP6MXZXTRB\",\"WARC-Block-Digest\":\"sha1:W5BK7WNML6MEOKVCRWNBK5T2V4Q7XAFT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575540518882.71_warc_CC-MAIN-20191209121316-20191209145316-00160.warc.gz\"}"}