Group Abstract Group Abstract

Message Boards Message Boards

Does NDSolve have an upper limit requirement of the number of equations?

Posted 8 years ago

I founded a series of master equations (equation set) in Fe-Cu-Ni system, where I should use the NDSolve function to solve these equations. The problem I encountered was that NDSolve raised an error when the number of equations in the set was over about 10000. The error said: ![enter image description here][1] So, does NDSolve have an upper limit requirement of the number of ODE equations? Or how should I fix the problem? My code is in the attachment. Looking forward to your help and much thanks!

POSTED BY: Lammond Wan
9 Replies

No problem, no worries.

I had an idea, which should work in principle. I'm pretty sure it fails because I ran out of memory. It actually almost completely freezes my laptop, and I have to force-quit Mathematica and several other applications to get back to where I can use it normally. That makes me think that the problem with your code is similar, except that your code fails semi-gracefully (no error reported, but does not freeze computer). Often running out of memory results in an error message, but I recall times when it did not.

I have only 16GB, but if you have more, the idea is to recast the system in terms of a vector variable cc comprising all your c[i, j] variables:

ca = CoefficientArrays[Sys[[;; Length@Bc, 2]], Through[Bc[t]]]
VectorQ[#["NonzeroValues"], NumericQ] & /@ ca  (* check there are no variables in the coefficients *)
(*  {True, True, True}  *)

ivs = Sys[[Length@Bc + 1 ;;, 2]];  (* initial values *)
VectorQ[ivs, NumericQ] (* check there are no variables in the values *)
(*  True  *)

MemoryConstrained[
 NDSolve[{
  cc'[t] == Fold[#1.cc[t] + #2 &, Reverse@ca], (* reconstruct polynomial RHS of the ode system (Horner's method) *)
  cc[0] == ivs}, 
  cc, {t, tMin, tMax; 0.001}(*Method->"StiffnessSwitching", MaxSteps -> Infinity*)],
  4*^9,   (* put your memory limit here *)
  "ran out of memory"]
(*  "ran out of memory"  *)

Should you be able to get a solution this way, the output value of the interpolation function will be a vector whose components correspond to the variables in Bc in the same order.

POSTED BY: Michael Rogers

By solving, I mean something like

Solve[Sys, D[Through[Bc[t]], t]]

As for "As you can see in my code,..." actually, no I couldn't see. I didn't try. Do you really expect someone to closely analyze so much code and the 10000 equations you said it produced?

POSTED BY: Michael Rogers
Posted 8 years ago

Sorry to express it that way, my English is so poor that I can't describe what I mean to say correctly. No doubt I should fix my problem myself, and I'm really appreciate your help. Thank you very much!

POSTED BY: Lammond Wan

Try add option to NDSolve:

 Method->{"EquationSimplification"->"Residual"}

Did it help?

POSTED BY: Mariusz Iwaniuk
Posted 8 years ago

Wow, the error disappears! I will check the correctness of the answers later, but I need to thank you at first. Moreover, how does it works by setting the method of equation simplification?

POSTED BY: Lammond Wan

You can find the answer how it works probably here -> Differential-Algebraic Equations -> Introduction

Regards,MI

POSTED BY: Mariusz Iwaniuk
Posted 8 years ago

Thank you very much, it's very useful and helpful. I guess the key to the problem is that it will take a long long time to get a explicit formula when the number of equations gets so big, therefore residual form is a better way to solve the question. Thanks a lot.

POSTED BY: Lammond Wan
POSTED BY: Michael Rogers
Posted 8 years ago
POSTED BY: Lammond Wan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard