Analyzing the time complexity of Trapezium algorithm by Sequential and Parallel Computing.
The trapezoidal rule is a technique for numerical integration, approximating the definite integral by representing the region under the function graph as trapezoids and calculating their areas.
function trapezium_integral(a, b, n, function_evaluator):
# Calculate the width of each trapezoid
range_width = (b - a) / n
# Initialize sum to store the total area
area_sum = 0.0
# Iterate through each partition
for i in range(1, n):
# Calculate the x-coordinate within the partition
x_coordinate = a + i * range_width
# Evaluate the function at the current x-coordinate and add to sum
area_sum = area_sum + function_evaluator(x_coordinate)
# Add the average of the function values at the endpoints
area_sum = area_sum + (function_evaluator(a) + function_evaluator(b)) / 2.0
# Multiply by the width of each trapezoid and the reciprocal of the number of partitions
result = area_sum * range_width / float(n)
# Return the calculated result
return result
function parallel_trapezium_integral(a, b, n, f):
# Calculate the width of each trapezoid
range_width = checkParamsGetRange(a, b, n)
# Use parallel processing to calculate the sum of function values
sum_of_function_values = parallel_sum(i -> f.eval(a + i * range_width / n), 0 to n-1)
# Add the average of the function values at the endpoints
sum_of_function_values = sum_of_function_values + (f.eval(a) + f.eval(b)) / 2.0
# Multiply by the width of each trapezoid and the reciprocal of the number of partitions
result = sum_of_function_values * range_width / float(n)
# Return the calculated result
return result
src/
contains the Java codeNumericalIntegration.java
: Java code for the algorithmFPFunction.java
: Java interface for the algorithmMain.java
: Testing purposeslogs.txt
: Testing dataset
Plot/
contains the Python code for the plotmain.py
: Main Python file using packages likecsv
,matlib
,pyproject.toml
, andpoetry.lock
to create the plot of the computed datasetlogs.txt
: Testing dataset
- We used NVIDIA's 2070 GPU to test 100,000,000 partitions on both implementations.
- Tested up to 100,000,000 of input size on our GPU.
The trapezium algorithm, tested with 100,000,000 partitions, exhibits O(n) time complexity in both sequential and parallel forms. The parallel version, leveraging sub-threads, demonstrates faster execution while maintaining the same O(n) time complexity.
- Advisor: Prof. Mohammed Abdelrahim of the California State University, Northridge
- Contributors: Roy Ananth, Sambahangphe Mishek, Shea Jackson, Ng Sunnathan, and Desai Param.