1

Question: Is there a command in mathematica that can take a decimal input, and output it into its exact form?

The question arose when I tried to use this command:

x = NSolve[Sum[h(An+B)/(C^n) /. A →(3/2)Sqrt[2]  /. C→ -2^9 /. h → (2n)!^3 / n!^6, 
    {n, 0, 50}] == 1/Pi, B, 30]

And got a decimal output of approximately $0.353553390593\ldots$. According to this website (where I got the approximation from), that is equal to $(1/4)\sqrt2$.

And my Mathematica does not recognize the command Recognize[x,k,v] so I am completely lost.

I am also relatively new to Mathematica. The output of the code should give $0.353553390593\ldots$ But whenever I enter it in, I get a bunch of errors that say this is protected. When I change the variables, I get an approximation greater than $1$. What is wrong with the coding that I'm entering in?

Frank
  • 113
  • 5

1 Answers1

4
RootApproximant[0.353553390593, 2]

Mathematica graphics

Rationalize may sometimes of use too:

Rationalize[0.353553390593, 0.00001]
(* 134/379 *)

% // N
(* 0.353562 *)
Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
  • Is it possible for you to add what was wrong with my piece of coding? Everything seems alright, yet Mathematica says some things are protected and there is an error dispatch... – Frank Nov 25 '16 at 22:51
  • 1
    @Frank Unless you still have Mathematica version 5 (current version is 11.01) NumberTheory`Recognize` won't work for you. See http://reference.wolfram.com/language/Compatibility/tutorial/NumberTheory/Recognize.html. – Sjoerd C. de Vries Nov 25 '16 at 23:01
  • No, I meant this: x = NSolve[Sum[h(An+B)/C^n /. A →(3/2)Sqrt[2] /. C→ -2^9 /. h → (2n)!^3 / n!^6, {n, 0, 50}] == 1/Pi, B, 30] – Frank Nov 25 '16 at 23:06
  • @Frank Seperate An and Cn with a space to make it a multiplication, and don't create an arrow symbol from outside of Mathematica. Use -> (Mathematica will replace it automatically with an arrow if you type the next character). Also, don't use uppercase variables as they may conflict with built-ins (C is one). – Sjoerd C. de Vries Nov 25 '16 at 23:10
  • Okay, I did that with x = NSolve[Sum[h(pn+q)/r^n /. p ->(3/2)Sqrt[2] /. r-> -2^9 /. h -> ((2n)!^3) / (n!^6), {n, 0, 50}] == 1/Pi, q, 30] and got the output $q$ as $q=1.0150800842861232878334064341(0.318\ldots - 0.98\ldots pn)$ With the $\ldots$ meaning a significant amount of other characters. I'm confused, because this doesn't give the number I was looking for. – Frank Nov 25 '16 at 23:34
  • @Frank Because you have pn which should be p*n (or p n - the space is interchangeable with *). – corey979 Nov 26 '16 at 00:19
  • @corey979 ooohhhh!!! Thank you! Now it works... – Frank Nov 26 '16 at 00:24