debugging - bug in nthroot using fixedpoint -


My attempt is to exercise 1-45 from the structure and interpretation implemented in Haskell:

  Fixed point :: (double-> double) - & gt; Double - & gt; Double - & gt; Double Fixed Points Estimated | Error & gt; Abs next estimate = next | Otherwise = Fixed point F is the next count where next = F is approximate average: double - & gt; Double - & gt; Double average A B = (a + b) / 2 avgdamp :: (double -> double) - & gt; (Double -> Double) avgdamp f = \ x - & gt; Average X (FX) log2 :: double - & gt; Repeat double log2 = (/ log2): (a-> a) - & gt; Int - & gt; (A-> A) Repeated F n = \ x - & gt; (Repeating fx) !! N nthroot :: int - & gt; Double - & gt; Double - & gt; Double Nathroot NX IRE = Fixed point (Repeated Egampamp DesignsED $ EKN) 1.0 Where to Be Reflected = Floor $ log2 $ from Integral - Experimentally determined eqn = \ y - & gt; X / Y ^ (N-1)   

I tested the procedures one by one, they seemed OK. I have solved 3 blogs on which the solutions are posted and my implementation corresponds with some minor exceptions like language and I use clear error logic.

Still I get harsh results from nthroot, and I do not have a clue.

  & gt; Nthroot 2 16 0.000000001 5.1911764705882355 & gt; Nthroot 3 8 0.000001 2.447530864197531 & gt; Nthroot 3 27 0.001 7.0688775510204085 & gt; Nthroot 5 32 0.001 6.563864764681383   

Or in this case I owecave [0..16] than expected to get back (approximation)

  & Gt; [0:16]. ^ 2 (1/2). ^ 2 ans = 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 10.00000 11.00000 12.00000 13.00000 14.00000 15.00000 16.00000   

But

  & gt; Map (^ 2) $ Map (\ x - & gt; nthroot 2 x 0.000001) [0..16] [0.25,1.0,2.006944444444444,3.0625,4.2025,5.4444444444444455,6.79719387755102,8.265625,9.852623456790123,11.559999999999999131388946280991735,15.340277777777777, 17.41457100591716, 19.612244897959187,21.933611111111112,24.37890625,26.94831314878893]   

Any welcome of what might be behind these bad results.

The function app becomes harder than any other infix operator. Therefore,

  abs next - guess == (abs next) - estimate   

which is not exactly what you want if you fix this problem , Your algorithm works fine.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -