Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to be able to find low-complexity algebraic approximants to decimal numbers. For example, 1.41 can be approximated as a solution to the polynomial x^2==2. There is a Mathematica function RootApproximant that seems like it should be able to do this approximation. However, I can't get it to work. RootApproximant[N[Sqrt[2]] returns $\sqrt{2}$ correctly, but RootApproximant[1.41] doesn't - it prefers to approximate it as 141/100.

Presumably I need to tell it to lower the accuracy it's aiming for. There is an option called "DegreeCost" that can be passed, but I can't work out how to use that to achieve my goal.

share|improve this question
    
Note that RootApproximant[1.4142, 7] is Sqrt[2] –  belisarius Mar 25 '13 at 12:49
1  
How about changing the precision of the input: RootApproximant[1.41`3] –  Simon Woods Mar 25 '13 at 12:54
add comment

1 Answer 1

Though RootApproximant is doing the right thing for $1.41$, if you persist to get some polynomial what about adding some random precision. Try this!

TrickApprox[loPric_?NumericQ, degree_?IntegerQ, degreeCost_: 2] := Module[{val}, 
  val = ToExpression@(ToString@loPric <>ToString@FromDigits@RandomInteger[{0, 4}, 8]);
  RootApproximant[val, degree, Method -> {"DegreeCost" -> degreeCost}]
 ]

Now test it for a cubic polynomial.

TrickApprox[1.41, 3]

Root[-5765 + 7694 #1 - 2705 #1^2 + 104 #1^3 &, 1]

N[%, 3]

1.41

If you increase the DegreeCost using the third argument RootApproximant will try not to include higher degree terms in the approximation.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.