MTH643 — Final Term Summary (Lectures 23–24)
📘 Lecture 23 — Simpson’s 3/8 Rule
📖 Overview: This lecture covers the numerical integration technique known as Simpson's 3/8 Rule. It explains the algorithm, the necessary condition that the number of sub-intervals must be a multiple of 3, and provides a complete MATLAB implementation for approximating definite integrals. This method is valuable for obtaining more accurate integral approximations than simpler rules when dealing with smooth functions.
🗂️ Topics Covered
The lecture presents the MATLAB code for implementing Simpson’s 3/8 Rule. It covers input handling for the function, lower and upper limits, and the number of sub-intervals; a validation check ensuring n is a multiple of 3; loop structures to compute function values at each point; separation of interior points into those at positions that are multiples of 3 and others; and the final formula application to compute the integral approximation.
📝 Lecture Summary
Simpson’s 3/8 Rule
The lecture provides a complete MATLAB implementation of Simpson's 3/8 Rule for numerical integration. The code begins by clearing the workspace and defining the function to be integrated using an anonymous function handle.
The user is prompted to enter the lower limit a, upper limit b, and the number of sub-intervals n. A critical validation check ensures that n is a multiple of 3, because Simpson’s 3/8 Rule requires the interval to be divided into segments of three sub-intervals each.
The step size h is computed as (b-a)/n. The code then generates vectors x(k) and y(k) containing the x-coordinates and corresponding function values at each of the n points.
Two summation variables are initialized: so for the sum of function values at positions that are not multiples of 3, and sm3 for the sum of function values at positions that are multiples of 3. The loop iterates from k=2 to k=n-1, excluding the endpoints. If k is divisible by 3 (using the rem function), the y-value is added to sm3; otherwise, it is added to so.
🔑 Definition — Simpson’s 3/8 Rule: A numerical integration method that approximates the definite integral by fitting cubic polynomials to groups of four equally spaced points, using weights of 3/8 of the step size for the endpoints, 9/8 for points not at multiples of 3, and 6/8 for points at multiples of 3.
📐 Formula: answer = (3*h/8) * (f(a) + f(b) + 3*so + 2*sm3)
→ This formula multiplies the weighted sum of function values by 3h/8 to compute the approximate integral.
📌 Example: For the function f(x)=1/(1+x) with limits a=1 to b=2 and n=21, the code computes h=(2-1)/21 ≈ 0.04762. Since 21 is a multiple of 3, the validation passes. The loop computes 21 function values, finds the sums of others and multiples of 3, and the final answer is 0.381665.
💡 Why this matters: Simpson’s 3/8 Rule provides a higher-order approximation than Simpson’s 1/3 Rule, making it more accurate for functions with smooth behavior over the interval. However, it requires the number of sub-intervals to be a multiple of 3, which is an important constraint to remember in implementation.
⭐ Key Takeaways
The most critical points from this lecture are: the number of sub-intervals n must be a multiple of 3 for Simpson’s 3/8 Rule to work; the formula uses weights of 3 for interior points not at positions divisible by 3 and weight 2 for interior points at positions divisible by 3; the MATLAB code includes proper validation to reject invalid n values; the step size h is computed as (b-a)/n ; and the final approximation for the example integral from 1 to 2 of 1/(1+x) with 21 sub-intervals is 0.381665. Understanding the weighting scheme and the divisibility requirement is essential for correctly applying this method.
🧠 Quick Revision Questions
- What is the required condition on the number of sub-intervals n for Simpson’s 3/8 Rule?
- In the MATLAB code, what is the purpose of the
remfunction? - What are the weights assigned to interior points that are multiples of 3 versus other interior points?
- For the function f(x)=1/(1+x), with a=1, b=2, and n=21, what is the computed integral approximation?
- How is the step size h calculated in the Simpson’s 3/8 Rule implementation?
📘 Lecture 24 — Bisection Method
📖 Overview: This lecture introduces the Bisection Method, a fundamental numerical technique for finding roots of continuous functions. It explains the method's iterative approach of repeatedly halving intervals to bracket a root, making it essential for solving equations when analytical solutions are difficult or impossible.
🗂️ Topics Covered
The lecture covers the fundamental principle of the bisection method for solving f(x)=0 where f is continuous with opposite signs at interval endpoints. It explains the iterative process of computing midpoints, evaluating function values, and selecting subintervals that guarantee root bracketing. The lecture includes a complete step-by-step example using the polynomial f(x)=x³−x−2, and provides MATLAB code implementing the algorithm with convergence checking.
📝 Lecture Summary
Bisection Method
The method is applicable for numerically solving the equation f(x)=0 for the real variable x, where f is a continuous function defined on an interval [a, b] and where f(a) and f(b) have opposite signs.
At each step the method divides the interval in two by computing the midpoint c = (a+b)/2 of the interval and the value of the function f(c) at that point. Unless c is itself a root, there are now only two possibilities: either f(a) and f(c) have opposite signs and bracket a root, or f(c) and f(b) have opposite signs and bracket a root. The method selects the subinterval that is guaranteed to be a bracket as the new interval to be used in the next step.
🔑 Definition — Bracket: An interval [a,b] where f(a) and f(b) have opposite signs, guaranteeing at least one root exists within the interval (by the Intermediate Value Theorem for continuous functions).
💡 Why this matters: The bisection method is guaranteed to converge to a root as long as the initial interval contains a sign change, making it one of the most reliable root-finding methods.
Iterative Scheme
The input for the method is a continuous function f, an interval [a, b], and the function values f(a) and f(b). The function values are of opposite sign. Each iteration performs these steps:
- Calculate c, the midpoint of the interval: c = (a+b)/2
- Calculate the function value at the midpoint, f(c)
- If convergence is satisfactory (that is, c - a is sufficiently small, or |f(c)| is sufficiently small), return c and stop iterating
- Examine the sign of f(c) and replace either (a, f(a)) or (b, f(b)) with (c, f(c)) so that there is a zero crossing within the new interval
📐 Formula: c = (a+b)/2 → The midpoint calculation for each iteration that divides the current interval in half.
Example
Suppose that the bisection method is used to find the root of the polynomial: f(x) = x³ - x - 2
First, two numbers a and b have to be found such that f(a) and f(b) have opposite signs. For the above function, a=1 and b=2 satisfy this criterion, as:
- f(1) = -2
- f(2) = 4
Because the function is continuous, there must be a root within the interval [1, 2].
In the first iteration, the end points of the interval which brackets the root are a₁=1 and b₁=2, so the midpoint is: c = (a+b)/2 = 1.5 f(c) = -0.125
Because f(c) is negative, a=1 is replaced with a=1.5, so the new interval becomes [1.5, 2].
📌 Example: For f(x)=x³−x−2 with initial interval [1,2]: f(1)=-2 (negative), f(2)=4 (positive). First midpoint c=1.5, f(1.5)=-0.125 (negative). Since f(1.5) and f(2) have opposite signs, the new interval is [1.5, 2].
Code
f=@(x)x^3-x-2;
a=1;
b=2;
if f(a)*f(b) > 0
disp('There is no change of sign');
return
end
tol=10^-5;
disp(' Iter. a b c');
i=1;
while(abs(a-b)>=tol)
c=(a+b)/2;
if(f(c)==0)
fprintf('Root of function is %f \n',c)
return
end
fprintf('%2i \t %f \t %f \t %f \n',i, a, b, c)
if(f(a)*f(c)>0)
a=c;
else
b=c;
end
i=i+1;
end
m=(a+b)/2
fprintf('Root lies at c= %f \n',m)
The code implements the bisection algorithm with: initial sign checking to ensure a bracket exists, a tolerance of 10⁻⁵ for convergence, and updating either endpoint a or b based on the sign of f(a)*f(c). If the product is positive, f(a) and f(c) have the same sign, so the root is between c and b, and a is replaced with c. If negative, b is replaced with c.
🔑 Definition — Tolerance (tol): The stopping criterion for the algorithm, set to 10⁻⁵ in this code, meaning iterations continue until the interval width |a-b| is less than this value.
⭐ Key Takeaways
The bisection method requires a continuous function with opposite signs at interval endpoints, guaranteeing at least one root exists. Each iteration halves the interval by computing the midpoint and selecting the subinterval where the function changes sign. The method is reliable but converges linearly, requiring many iterations for high precision. The algorithm stops when either the function value at the midpoint is exactly zero or the interval width becomes smaller than the specified tolerance. The MATLAB code demonstrates the complete implementation with sign checking, iteration tracking, and convergence criteria.
🧠 Quick Revision Questions
- What condition must f(a) and f(b) satisfy for the bisection method to work?
- How is the midpoint c calculated at each iteration?
- In the example f(x)=x³−x−2 with initial interval [1,2], what was f(1.5) and why was a replaced?
- What does the condition f(a)*f(c) > 0 tell us about the location of the root?
- Why is the bisection method guaranteed to converge, unlike some other numerical methods?