Is it possible to use NDSolve with Rational numbers instead of Real? I use all rational numbers for the constants I provide to NDSolve, but it always seems to make computations with Real numbers. My question is less about some specific code and more about how NDSolve works, thanks!

  • $\begingroup$ Welcome to the Mathematica Stack Exchange. Please add to your post the Mathematica code that you have tried out so far. $\endgroup$
    – Syed
    Jan 1 at 7:43
  • 2
    $\begingroup$ Rational numbers will allow you to set the WorkingPrecision to be high, but I believe the computation will always be decimal numbers. $\endgroup$
    – Bill Watts
    Jan 1 at 8:05
  • 1
    $\begingroup$ @amzon-ex It is possible to integrate with rational numbers, but we didn't see your equations yet:) $\endgroup$ Jan 1 at 13:53
  • 2
    $\begingroup$ A Rational number is exact, and you need an exact solver, such as DSolve, to keep results exact. NDSolve is an approximate (numerical) solver and uses floating-point rationals (a.k.a. Real numbers, or sometimes Complex) to approximate the solution. Of course, (binary) floating-point does not represent all rationals, only those whose denominators are powers of 2. But they are rational numbers, technically. You can convert them in the solution to their Rational equivalents with SetPrecision[x, Infinity]; or Rationalize[x, 0] to convert to a rational approximation. $\endgroup$
    – Michael E2
    Jan 1 at 17:10
  • 1
    $\begingroup$ Yes, that's right. Only NDSolve solves diff. eqs. numerically, and it uses only machine floating-point numbers or "bignum," arbitrary-precision numbers. $\endgroup$
    – Michael E2
    Jan 3 at 15:27

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.