# Rational numbers in NDSolve

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!

• Welcome to the Mathematica Stack Exchange. Please add to your post the Mathematica code that you have tried out so far.
– Syed
Jan 1 at 7:43
• Rational numbers will allow you to set the WorkingPrecision to be high, but I believe the computation will always be decimal numbers. Jan 1 at 8:05
• @amzon-ex It is possible to integrate with rational numbers, but we didn't see your equations yet:) Jan 1 at 13:53
• 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. Jan 1 at 17:10
• Yes, that's right. Only NDSolve solves diff. eqs. numerically, and it uses only machine floating-point numbers or "bignum," arbitrary-precision numbers. Jan 3 at 15:27