Introduction to Scientific Computing

Assignment 2

Note: Please do your programming in Matlab, document thoroughly! The code must

compile on one of the lab machines with your instructions.

Instructions

During lecture we discussed a number of integral quadrature methods. Each method calculates a

set of weight/position pairs {π€π€ππ, π₯π₯ππ}, for integrating a curve.

οΏ½ ππ(π₯π₯)ππππ β οΏ½π€π€ππππ(π₯π₯ππ)

ππ

ππ=1

ππ

ππ

1. Implement the following Newton-Cotes methods for finding {π€π€ππ, π₯π₯ππ} pairs

a. Constant interpolant (composite midpoint rule) for ππ = 17,33,65,129,257,513

b. Linear interpolant (composite trapezoid rule) for ππ = 17,33,65,129,257,513

c. Quadratic interpolant (composite Simpson formula) for ππ = 17,33,65,129,257,513

2. Implement the following Gaussian methods given by the following {π₯π₯ππ, π€π€ππ} pairs.

Note: the points are defined on [-1,1] and have to be mapped onto [a,b].

π΅π΅ ππππ ππππ

1 0 2

2 Β±1/β3 1

3

0 8/9

Β±οΏ½3/5 5/9

4

Β±οΏ½(3 β 2οΏ½6/5)/7 (18 + β30)/36

Β±οΏ½(3 + 2οΏ½6/5)/7 (18 β β30)/36

5

0 128/225

Β±

1

3

οΏ½5 β 2οΏ½10/7 (322 + 13β70)/900

Β±

1

3

οΏ½5 + 2οΏ½10/7 (322 β 13β70)/900

3. Calculate the integral for the function below using all of the methods above.

2

οΏ½ 1 + sin(π₯π₯) β cos οΏ½

2π₯π₯

3 οΏ½ β sin(4π₯π₯) ππππ

2ππ

0

β’ Report the results and create a convergence plot for the 3 Newton-Cotes formulas (a) (b)

and (c) above for ππ = 217,33,65,129,257,513 that shows how quickly the methods go to a

common final value.

o Which of the Newton-Cotes formulas converges fastest? Is that in line with the theoretical

error? Why?

o

β’ Estimate the error for the Trapezoidal Rule and Simpsonβs Rule by estimating the appropriate

derivatives and using the explicit from of the error. Now estimate the errors by using

Richardson Extrapolation . Which error estimates are more accurate?

β’ Report the results for ππ = 2, 3, 4, 5 for the Gaussian quadratures given above

o The Gaussian quadratures are high-order functions, yet they donβt do a good job

approximating the integral, why?

o What could be done to make the Gaussian quadratures give better results?

What to turn in

For these assignments, we expect both SOURCE CODE and a written REPORT be uploaded as a zip

or tarball file to Canvas.

β’ Source code for all programs that you write, thoroughly documented.

o Include a README file describing how to compile and run your code.

β’ Your report should be in PDF format and should stand on its own.

o It should describe the methods used.

o It should explain your results and contain figures.

o It should also answer any questions asked above.

o It should cite any sources used for information, including source code.

o It should list all of your collaborators.

This homework is due on February 21 by 11:59 pm. If you don’t understand these directions, please

send questions to me or to the TAs or come see one of the TAs or the instructor during office hours

well in advance of the due date.

Sale!