## Transcribed Text

ASSIGNMENT 4
The Newton-Cotes formulas are a family of integration techniques that are using in numerical integration.
The idea is to approximate the integrand, ๐๐, by a polynomial, ๐๐๐๐, fit to ๐๐ points of ๐๐ over [๐๐, ๐๐].
๏ฟฝ ๐๐(๐ฅ๐ฅ) ๐๐๐ฅ๐ฅ
๐๐
๐๐
โ ๏ฟฝ ๐๐๐๐(๐ฅ๐ฅ) ๐๐๐๐
๐๐
๐๐
Note that ๐๐๐๐ is an (๐๐ โ 1)-degree polynomial.
Fitting ๐๐ by 2-points, i.e., a straight line, yields the trapezoid rule:
๏ฟฝ ๐๐(๐ฅ๐ฅ) ๐๐๐ฅ๐ฅ
๐๐
๐๐
โ ๏ฟฝ ๐๐2(๐ฅ๐ฅ) ๐๐๐๐
๐๐
๐๐
= ๏ฟฝ ๏ฟฝ(๐ฅ๐ฅ โ ๐๐)
(๐๐ โ ๐๐)
๐๐(๐๐) + (๐ฅ๐ฅ โ ๐๐)
(๐๐ โ ๐๐)
๐๐(๐๐)๏ฟฝ ๐๐๐๐
๐๐
๐๐
= ๏ฟฝ
๐๐ โ ๐๐
2 ๏ฟฝ [๐๐(๐๐) + ๐๐(๐๐)]
Fitting ๐๐ to 3-points, i.e., a parabola, yields Simpsonโs rule:
๏ฟฝ ๐๐(๐ฅ๐ฅ) ๐๐๐ฅ๐ฅ
๐๐
๐๐
โ ๏ฟฝ ๐๐3(๐ฅ๐ฅ) ๐๐๐๐
๐ฅ๐ฅ2
๐ฅ๐ฅ0
= 1
3 โ(๐ฆ๐ฆ0 + 4๐ฆ๐ฆ1 + ๐ฆ๐ฆ2)
Where โ = (๐๐ โ ๐๐)/2 and:
(๐ฅ๐ฅ0, ๐ฆ๐ฆ0) = ๏ฟฝ๐๐, ๐๐(๐๐)๏ฟฝ
(๐ฅ๐ฅ1, ๐ฆ๐ฆ1) = ๏ฟฝ๐๐ + โ, ๐๐(๐๐ + โ)๏ฟฝ
(๐ฅ๐ฅ2, ๐ฆ๐ฆ2) = ๏ฟฝ๐๐ + 2โ, ๐๐(๐๐ + 2โ)๏ฟฝ = ๏ฟฝ๐๐, ๐๐(๐๐)๏ฟฝ
Extending this to ๐๐-points, โ = (๐๐ โ ๐๐)/(๐๐ โ 1) and:
(๐ฅ๐ฅ0, ๐ฆ๐ฆ0) = ๏ฟฝ๐๐, ๐๐(๐๐)๏ฟฝ
(๐ฅ๐ฅ1, ๐ฆ๐ฆ1) = ๏ฟฝ๐๐ + โ, ๐๐(๐๐ + โ)๏ฟฝ
โฎ
(๐ฅ๐ฅ๐๐, ๐ฆ๐ฆ๐๐) = ๏ฟฝ๐๐ + ๐๐โ, ๐๐(๐๐ + ๐๐โ)๏ฟฝ
โฎ
(๐ฅ๐ฅ๐๐โ1, ๐ฆ๐ฆ๐๐โ1) = ๏ฟฝ๐๐ + (๐๐ โ 1)โ, ๐๐(๐๐ + (๐๐ โ 1)โ)๏ฟฝ = ๏ฟฝ๐๐, ๐๐(๐๐)๏ฟฝ
The following table gives the results up to a fourth-degree polynomial
๐๐-Degree Formula Name
1
โ
2 (๐ฆ๐ฆ0 + ๐ฆ๐ฆ1) Trapezoid Rule
2 โ
3 (๐ฆ๐ฆ0 + 4๐ฆ๐ฆ1 + ๐ฆ๐ฆ2) Simpsonโs Rule
3
3
8 โ(๐ฆ๐ฆ0 + 3๐ฆ๐ฆ1 + 3๐ฆ๐ฆ2 + ๐ฆ๐ฆ3) Simpsonโs 3/8 Rule
4
2
45 โ(7๐ฆ๐ฆ0 + 32๐ฆ๐ฆ1 + 12๐ฆ๐ฆ2 + 32๐ฆ๐ฆ3 + 7๐ฆ๐ฆ4) Booleโs Rule
Part I โ Single Interval
Create a function that outputs the approximate integral of ๐๐, over [๐๐, ๐๐] using a polynomial of degree ๐๐ โค 4.
The function call should look like newtonCotes(f,a,b,n).
Part II โ Multiple Subintervals
Create a function that outputs the approximate integral of ๐๐, over [๐๐, ๐๐] using a polynomial of degree ๐๐ โค 4,
by splitting the interval [๐๐, ๐๐] to ๐๐ equi-spaced subintervals. The function call should look like
CompositeNC(f,a,b,n,m)

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

function Q=newtoncotes(f,a,b,n)

n1=n+1;

x=linspace(a,b,n1)';

h=x(2)-x(1); g=f(x);

endpts=g(1)+g(n1);

nodes=n;

switch nodes

case{1} % Trapezoidal Rule

Q=(h/2)*(endpts);

case{2} % Simpson's Rule

Q=(h/3)*(endpts+4*(g(2)))...