Computer Science(Scheme Question)

profilemnjxndj2i02

1.

;; ;;  Write a RECURSIVE function `(eval-polynomial coefficients x)` ;;  that accepts a list (a0, a1, ..., a_n) of n+1 coefficients, ;;  and returns result of evaluating the order-n polynomial ;;      p(x) = a0 + a1 x + a2 x^2 + ... + a_n x^n. ;;  If the list of coefficients is empty, ;;  then p(x) should return zero. ;; ;;;;;;;;; 

(define (eval-polynomial coefficients x)

;; Need fill in! ) ;;;;;;;;;;;;; ;; Tests  (define (println s) (begin (display s) (newline)))  (println  (eval-polynomial `() 5)  ; Expext 0  )  (println  (eval-polynomial `(10 3 -4 2) 5)  ; Expect 175  )   

(println  (eval-polynomial `(10) 3) ; Expect 10  )  

2.

;; ;;  Write a function (polynomial coefs) that accepts a list of coefficients, ;;  but instead of evaluating the polynomial immediately it returns a unary ;;  function p(x) that can be used to evaluate the polynomial ;; ;;  You may not use your solutiomn from before. ;;  Your solution should recursively use `polynomial`. ;;;;;;;;; 

(define (polynomial coefs) 0 )  ;;;;;;;;;;;;; ;; Tests  (define (println s) (begin (display s) (newline)))  (println  ((polynomial `()) 5)  ; Expext 0  )  (println  ((polynomial `(10 3 -4 2)) 5)  ; Expect 175  )   

(println  ((polynomial `(10)) 3) ; Expect 10  )

    • a day ago
    • 10
    Answer(1)

    Purchase the answer to view it

    NOT RATED
    • attachment
      SchemeQuestion.docx
    • attachment
      PlagiarismReport-SchemeQuestion.pdf
    • attachment
      scheme.txt
    Bids(101)