Applix) or the SGIs (say Rapport),
especially since you will probably want to include some of the images
in the first lab. See one of us or one of the lab assistants if you
need help using one of these word processors.
Please be aware that your lab report will not (in general) contain the same sections as this one. Structure your report logically with sections appropriate to your lab assignment.
See this must read for detailed suggestions on how to write lab reports in computer science courses.
Chris Cross
MC27 Lab 1
February 31, 1995
Counting Real Roots of Quadratics
Introduction
------------
Computing the real roots of a quadratic equation on a computer can be
done using basic high school mathematics techniques. In this lab, we
demonstrate the method by computing the real roots of a quadratic
equations in Scheme. Part 1 consists of the code, part 2 discusses my
testing and lastly there are some concluding remarks.
Part 1: Number of real roots of a quadratic
-------------------------------------------
In this part of the lab, I designed a procedure to compute how many
real roots a quadratic equation has. Remembering that this could be
determined by computing the discriminant of the equation and then
testing that discriminant, I broke the problem into those two parts:
(define num-real-roots
(lambda (a b c) ;how many real roots does ax^2+bx+c=0 have?
(num-real-roots-from-discriminant (discriminant a b c))))
The two auxiliary routines used by the above both straightforwardly
reflect my memories from high school:
(define discriminant
(lambda (a b c)
(- (square b) (* 4 a c))))
(define num-real-roots-from-discriminant
(lambda (d)
(cond ((< d 0) 0)
((= d 0) 1)
((> d 0) 2))))
Part 2: Testing
________________
The procedure square used above is from the book. A sample call to
square is shown here:
(square 7) ==> 49
I tested the real-roots procedure using one simple example falling
into each of the three cases. Note that I took care to use examples
in which the three arguments were different from one another, to
improve the chances of catching certain bugs.
My procedure worked in all three cases, as shown below:
Input Result
--------------- ------
(num-real-roots 1 2 3) 0
(num-real-roots 1 10 2) 2
(num-real-roots 2 16 32) 1
Conclusion
----------
It's a common perception that "useful" programs have to be long.
Determining the number of real roots of a quadratic equation is an
example of an unusual category of computations: those that are complex
enough to be worth automating, yet involve only a fixed amount of
computation. As this lab demonstrated, programs which mirror routine
mathematical calculations are quite straightforward to write.