Computer Science(Scheme Question)
mnjxndj2i021.
;; ;; 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 )
- 3 years ago
- 10
Purchase the answer to view it
- SchemeQuestion.docx
- PlagiarismReport-SchemeQuestion.pdf
- scheme.txt