# CSC190: Computer Algorithms and Data Structures Assignment 1

\$30.00

## Description

Part 1: Evaluating a continuous function
This part requires you to expand the function f located in the a1Part1.c file.
• One argument x of type float is passed to this function.
1
• This function will return a value of type float.
• The polynomial you will implement is f(x) = sin(x) + x
10 + (x − 1)2
• Please refer to the file Part1.txt for a sample result from this function.
• You can test your implementation of this function using the provided main.c file. As you are aware
from going through the preparation slides, in order to execute this program, all associated functions
must be compilable. Hence, ensure that before you test this function that other skeleton functions are
at bare minimum compilable. Then, compile all files using the command supplied in Sec 2. When you
examine the main.c file, you can observe that you must supply to the executable file the argument
‘1’ to invoke the f function (i.e. execute the program with ./run 1 after compilation).
Part 2: Implementing Numerical Integration using Simpson’s Method
This part is a continuation of Part 1. Here you will implement the function S located in a1Part2.c which
numerically integrates the function f in the interval [a, b] (i.e. R b
a
f(x)). Numerical integration is used in
solvers such as MATLAB in order to evaluate the integral of a function within a specified interval. The
Simpson’s method approximates the integral of a function by evaluating the following expression:
Z b
a
f(x) ≈
b − a
6
(f(a) + 4f(m) + f(b)) (1)
where m is the mid-point of the interval [a, b]. The Simpson’s method approximates the function f using a
third order polynomial. The error in this approximation is proportional to the fourth derivative evaluated
at ε ∈ [a, b] (i.e. f
4
(ε)). Hence if f is a third order polynomial, there will be no error introduced by this
numerical integration.
• Two arguments are passed to the function and these are the bounds of integration (i.e. [a,b]).
• The function will evaluate and return the approximate value of R b
a
f(x) in accordance to Eq. 1.
• main.c file can be used to test your implementation via the command ./run 2. Ensure that your
output matches the sample output provided in Part2.txt. You can integrate the expression f by
hand. Compute the correct value and check how different the result from this function is from the
actual value.