Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In a code base that is difficult to change for unrelated issues, I have many invocations of NDSolve that look like the following:

NDSolve[equations, variables, {t, 0, 100}, 
 Method -> {"ExplicitRungeKutta", "StiffnessTest" -> False}]

This has stopped working with Mathematica 9.0, because something is timing out (our problem appears similar to the one described here). The fix is to change the invocation to look like this:

NDSolve[eqns, vars, {t, 0, 100},
  Method -> 
   {"ExplicitRungeKutta", 
    "StiffnessTest" -> False, 
    "EquationSimplification"->"Solve"}]

I would like to be able to change the part of the Method option involving "EquationsSimplification" to "Solve" globally, in such a way that it won't be clobbered when a call leaves that option alone, but sets other options (like using the "ExplicitRungeKutta" method, or turning off "StiffnessTest"). This will allow me to fix things in an init.m file once and for all.

(Yes, I'm aware this is ugly and hacky, but the other approaches are probably less appealing.)

share|improve this question
    
FWIW, this (unlike e.g. "StiffnessTest") is not an option for any function in the NDSolve` context. So, it looks like you have to insert it at the top level. –  Oleksandr R. Jul 8 '13 at 18:11

1 Answer 1

So far, it's looking like we'll have to fall back on the common yet awful, fragile and hard-to-maintain solution of putting the following in our init.m files:

Unprotect[NDSolve];
NDSolve[before___,
   (Method -> meth_), after___] :=
  NDSolve[before,
    (Method ->
      Switch[meth,
       _String,
       {meth, "EquationSimplification" -> "Solve"},
       _List,
       Append[meth, "EquationSimplification" -> "Solve"]
       ]),
    after] /;
   ! FreeQ[meth, "ExplicitRungeKutta"] && 
    FreeQ[meth, "EquationSimplification" -> _];
Protect[NDSolve];

I'd really like to be able to solve this problem in almost any other way. At the risk of editorializing a little, I'm pretty displeased that the switch to Mathematica 9 has put us in the position of having to consider doing things like this, by breaking perfectly good, working code.

EDIT to improve the function a little based on @Teake Nutma's suggestion, so it's a little more robust.

share|improve this answer
    
I think this is the best way to go. You might improve robustness by throwing eqns_,ivars_,dvar_,before_ into a single before___, and throw in an If[$VersionNumber >= 9., ...] statement, but otherwise I don't see much room for improvement. –  Teake Nutma Jul 8 '13 at 14:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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