2014-09-23 LAB

posted Sep 23, 2014, 4:59 PM by Samuel Konstantinovich   [ updated Sep 23, 2014, 6:00 PM ]
Lab to be completed at home:

1. Write a function to calculate the discriminant of a quadratic. 
(disc A B C)
2. Use the disc function to write functions to calculate the roots of a quadratic. You must have two functions, one for the larger root, and the other for the smaller root:
(quadRootPos A B C)  and (quadRootNeg A B C)
examples:
(quadRootPos 1 5 6) evaluates to -2
(quadRootNeg 1 5 6) evaluates to -3
(quadRootPos 1 0 -1) evaluates to 1
(quadRootNeg 1 0 -1) evaluates to -1

BEFORE You start part 3, change your language to PrettyBig, or Swindle.

3. Functions can be passed as parameters just like values can.  Use this to make a single quadRoot function that takes a + or a - operator as one of the parameters so:
(quadRoot A B C f)  where f is either + or - , and A B C are the same as before.
(quadRoot 1 5 6 +) evaluates to -2
(quadRoot1 5 6 -) evaluates to -3
(quadRoot 1 0 -1 +) evaluates to 1
(quadRoot 1 0 -1 -) evaluates to -1

Comments