# ASSIGNMENT 4 The Newton-Cotes formulas are a family of integration...

## 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)

## Solution Preview

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)))...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

\$20.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available MATLAB for Physics Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.