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

## Question

Show transcribed text

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