0 Replies - 1180 Views - Last Post: 19 July 2010 - 10:22 AM

#1 Crunch  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

[Scheme] Polynomial evaluation - Horner's method

Posted 19 July 2010 - 10:22 AM

Description:
(define a (list 4 -2 1))

(define result (car a ) )

(define (loop x i i-max step)
  (if (<= i i-max)
    (begin    
      
        (set! result (+ (* result  x ) (list-ref a i) ) )
         
    (loop x (+ i step) i-max step))

))


(define Horner(lambda ( x )
                          
            (loop x 1 (- (length a ) 1) 1 ) 
            (display result) 
))


Is This A Good Question/Topic? 0
  • +

Page 1 of 1