Exercises 14.5 Homework
1.
Sometimes one needs an “open-ended” version of Newton-Cotes rules, which does not use the values of the function at the endpoints (because the function may not be defined at the endpoints). Find the coefficients in the integration rule
so that the rule is precise for \(x^0\text{,}\) \(x^1\text{,}\) and \(x^2\text{.}\) (You can use Matlab for solving the system of equations for the weights.)
2.
Apply the integration rule derived in the previous exercise to \(\int_{-1}^1 (1-x^2)^{-1/4}\,dx\text{.}\) How close is the result to the actual value of the integral (you can find it, for example, with WolframAlpha)?
3.
In a loop over n=2:10
, do the following. First, compute the weights for \(n\)-point Newton-Cotes rule (of the standard type, as in Example 14.3.1). Then use this rule to approximate \(\int_{-1}^1 e^x\,dx\text{.}\) After the loop ends you should have 9 approximations to this integral. Show how their accuracy changes with \(n\) by plotting the absolute value of the difference between the integral and approximation, as a function of \(n\text{.}\) Use semilogy
instead of plot
to show the plot on logarithmic scale.