472 Assignment 6
472 Assignment 6
472 Assignment 6
Instructions
Please note that the scripts contained in demoSimpsons.m and demoTrap.m must run
without error, otherwise your code will be given a grade of 0.
The report is an essential portion of this assignment. Please address each of the 3 points
given in the Analysis section of the assignment instructions (last page of the assignment). Be
concise; the purpose of the report is to address these 3 points and nothing else.
Any file other than the ones listed above is not necessary for submission.
Any MATLAB code used in your analysis can be copied directly into the report.
Background
The biggest drawback of composite quadrature rules is the dilemma of the step-size that will be
used. For example, if we have a monotonic function that increases at a steady rate, we may be
able to use a large step-size to obtain a highly accurate estimate of its integral while minimizing
computing time. However, this large step-size may fail miserably when applied to a wildly
varying function. In this case, we would prefer a smaller step-size. An even greater dilemma
occurs if we are faced with a function with both of these characteristics what would we do
then? We must look towards an adaptive approach where the function is recursively broken
down into smaller and smaller intervals, but only where necessary. An interval will be broken
down into two subintervals only if the integral done independently on the two subintervals is far
more accurate. This is known as adaptive quadrature.
Objectives
This assignment will cover the following topics:
1. Adaptive quadrature methods for numerical integration.
2.
3.
4.
5.
You are required to integrate an unknown function across a finite range using adaptive
quadrature. You will gain insight on how the adaptive algorithm works by creating visualizations
of its optimally-chosen intervals of integration.
Preliminary: The unknown function that you are given is positive within an interval [1, 9] and 0
elsewhere. Before moving on, it would be wise to have a look at it. It is a function of only one
variable (i.e., of the form
) and can be sampled at any point. This unknown function is
defined in f.m.
Task 1: Write a MATLAB function with the following description:
function estIntegral = integralSimpsons(f, a, b)
This function should be stored in a file named integralSimpsons.m. It should estimate integral
of a function across a specified interval using the Simpsons rule, where:
f a MATLAB function handle.
a scalar value defining the lower limit of integration.
b scalar value defining the upper limit of integration.
estIntegral the value of the estimated integral.
This function will be called recursively to perform the numerical integration. It will also return
the endpoints of the M subintervals formed throughout the process in an M-by-2 matrix
intervals. This function should be stored in a file named adaptiveSimpsons.m and it
should perform the following steps:
1. Find the midpoint of the current interval [a, b] and store the result in a variable c.
2. Apply Simpsons rule, using integralSimpsons twice on the unknown function
(pointed at by MATLAB function handle f): Once on the left subinterval [a, c], and
again on the right subinterval [c, b].
3. In the current recursion, we must check for the stopping criteria. Let
denote the
estimate of our integral across an interval
. If
where
Analysis
1. Compare the results obtained from adaptive Simpsons rule with those from the adaptive
trapezoid rule. In either case, why are the intervals chosen the way they are by the
algorithm? You may wish to vary the tolerances and re-run both cases to obtain
presentable result.
2. Compare the estimates for various tolerances with the MATLAB integral function,
which numerically evaluates the integral for a given function handle on a specified
interval. To get MATLAB to show more digits in your answer, type format long in
the terminal. This change may be reverted by typing format short, or simply
format, in the terminal.
3. Computational complexity is usually determined by the number of multiplications and
divisions. Since our function is unknown, we cannot accurately measure this. An
alternative is to measure the amount of time it takes to run our implementations
integrateSimpsons and integrateTrap on the unknown function. Use the
MATLAB tic and toc functions to perform the necessary measurements. Perform the
measurements many times and take the average to make sure they are reliable. Which
method is more computationally demanding? Why? Which method is more
computationally demanding in the context of the adaptive algorithm? Why?