2015-10-01

posted Oct 1, 2015, 5:31 AM by Samuel Konstantinovich   [ updated Oct 1, 2015, 5:49 AM ]
Goal: A better quadratic (add this on to lab02)

Do now:  Use this definition and evaluate the three expressions below
(define f (lambda (a b c)
            (+
              (* a b )
              (- b c ))))
(f 3 4 5)
(f (+ 1 2) 3 4)
(f (f 3 4 5) 6 7)

Demo:

(apply op a b); applies the operator op, onto the two values a and b.

(define apply (lambda (op a b) 
    (op a b) ) )
;This works when you use:
(apply + 3 4)  -> 7
(apply * 3 4)  -> 12
(apply - 3 4)  -> -1


Write the scheme function:

(infix a op b)   
;e.g.
(infix 1 + 2) -> 3
(infix 4 * 2) -> 8
(infix 1 - 2) -> -1

Extend lab02:

(findroot a b c plusminus)  -> results in the quadratic formula when used on 3 numbers and either the + or - operator.
e.g.
(findroot 1 4 3 +) ; is the same result as (posroot 1 4 3)
(findroot 1 4 3 -) ; is the same result as (negroot 1 4 3)

How can we simplify posroot and negroot using findroot?

Change your negroot and posroot to utilize findroot.

Comments