0
$\begingroup$

I have a fairly complex equation containing many terms, I can use the NDSolve for solving the differential equation for lesser terms (6400ish). But can't do it for let's say 10^4 terms, due to the error "$RecursionLimit::reclim: Recursion depth of 1024 exceeded." I modified the code (provided below) it to have a higher recursion limit, but it still treats the recursion limit to be 1024. Can someone please help me with the situation?

Clear[x]; (x = 
  x /. First[
    Block[{$RecursionLimit = 10^4},x= 
     NDSolve[{x'[t] == eqn, x[0] == x0}, Fraction[x], {t, 0, tF}, 
      WorkingPrecision -> 30, Method -> "StiffnessSwitching", 
      MaxSteps -> 10^5]]]);
$\endgroup$
5
  • $\begingroup$ Is there any chance that you could determine that your equation works out to n terms and fails at n+1 terms? And then look at exactly what that n+1 term is? If you can do that then move that term to the end and see if your equation possibly then works out to m terms and fails at m+1. And repeat until you have identified and isolated all your problem terms. Then show us what those problem terms are and how they are very different from all your non-problem terms. $\endgroup$
    – Bill
    Commented Feb 5 at 18:50
  • $\begingroup$ What's the definition of eqn? $\endgroup$
    – Chris K
    Commented Feb 5 at 18:55
  • 3
    $\begingroup$ Try it without the x=, which occurs in two places. Defining x in terms of itself is a good way to get infinite recursion. $\endgroup$
    – Goofy
    Commented Feb 5 at 20:45
  • $\begingroup$ What's the definition of Fraction[x]? $\endgroup$
    – Goofy
    Commented Feb 5 at 20:46
  • $\begingroup$ Thank you @Goofy, this solved the recursion problem, but for higher number of terms I am still getting stiffness issue or NDSolve failing and suggesting to use residual method. Bill the terms are of the form $\sum a\sin(\gamma x)e^{b(t-tf)}$, only a, b and $\gamma$ change. $\endgroup$
    – Bravyi
    Commented Feb 11 at 17:23

0