QuestionQuestion

Transcribed TextTranscribed 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 PreviewSolution 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)))...
$20.00 for this solution

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.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats