Assignment B
One Newton-Cotes rule that is not used often is called Boole's rule. Consider the integral \[\int_a^b f(x)\,dx\] where \(f\) is twice continuously differentiable. Let \(a=x_0\lt x_1\lt\dots\lt x_n=b\) be an equally-spaced partition of \([a,b]\), where we assume that \(n\) is evenly divided by 4. When \(h=(b-a)/n\) is the uniform width of the subintervals, the composite Boole rule is \[\int_a^b f(x)\,dx = \frac{4h}{90}\sum_{i=1}^{n/4} \left( 7f(x_{4i-4})+32f(x_{4i-3})+12f(x_{4i-2})+32f(x_{4i-1})+7f(x_{4i}) \right) + O(h^6). \] Write a Python function called boole that takes four arguments: an integrand function, the lower and upper limits of integration, and the value of \(n\), which returns the value of the Boole's rule approximation to the integral. Be sure your function tests whether \(n\) is divisible by 4. If not, it should print an error message, and return NaN (it is a thing in Numpy). If you prefer, you can use the raise keyword for this, but you do not have to.
This assignment is worth 35 points. Send the completed .py or .ipynb file containing the function as an attachment to an email message to the instructor by 9:00 AM on Thursday, 8 December. Remember that if you send a .py file, you must change the filename so that the extension is e.g. .txt, in order to get it through campus mail.
The last test will take place at the final exam time on
Tuesday, 12 December, from 1:30-3:30. It will be written as a one-hour (not
50 minute) exam, but you may have the full two hours for it.
In other respects it will be very like the other tests, but
comprehensive - it will emphasize Python, but cover all the
topics we have seen.
There is a
Sample Exam, but be aware that things will have changed somewhat
with the advent of ChatGPT.
Assignment A
is posted.