Академический Документы
Профессиональный Документы
Культура Документы
Assignment 5
Dr. Ming Ming Tan
McMaster University
1 Background
Consider a function f (x). If r is such that f (r) = 0 then r is said to be
the a root of f (x). One way to find a root of a continuous function is by
using the bisection method. The following describes the bisection method
for estimating a root of a continuous function f in the interval [a, b] within
a tolerance , where a < b and f (a) ∗ f (b) ≤ 0.
a+b
Step 1: Define m = 2 be the midpoint of the interval [a, b].
Step 2: If any of the values f (a), f (m) and f (b) are zero, then return the
corresponding point as solution and exit.
Step 3: If (b − a) ≤ , then return the value of a as solution and exit.
Step 4: If f (a) ∗ f (m) ≤ 0 then set m as the new b. Otherwise, set m as the
new a. Return to Step 1.
Next, we look at the definite integral of a function. The value of a definite
integral
Z b
f (x) dx
a
can be approximated, using the trapezoidal rule, by the summation
n
X f (xi−1 ) + f (xi ) b−a
∗
2 n
i=1
1
where
a = x0 < x1 < · · · < xn = b
and xi − xi−1 = (b − a)/n for all i with 1 ≤ i ≤ n. The approximation
becomes more accurate as the parameter n increases in value.
2 Assignment 5
The purpose of this assignment is to create a Haskell module for approxi-
mating the root and the definite integral of a function.
2.1 Requirements
1. The name of your Haskell file is Assign 5 YourMacID.hs where Your-
MacID is your actual MacID.
2. Your name, MacID, the date, and “Assignment 5” are given in com-
ments at the top of your file.
3. The first uncommented line of the file should be
2
2.2 Testing
Include in your file a test plan for all the functions mentioned above. The
test plan must include at least three test cases for each function. Each test
case should have following form:
Function: Name of the function being tested.
Test Case Number: The number of the test case.
Input: Inputs for function.
Expected Output: Expected output for the function.
Actual Output: Actual output for the function.